diff --git a/src/ms-core.ts b/src/ms-core.ts
index 227ccf0..1e0738c 100644
--- a/src/ms-core.ts
+++ b/src/ms-core.ts
@@ -421,7 +421,7 @@ export default class MobileSelect {
let tempHTML = "";
for (let i = 0; i < wheelsData.length; i++) {
// 列
- tempHTML += `
`;
+ tempHTML += ``;
tempHTML += this.getOptionsHtmlStr(wheelsData[i].data);
tempHTML += "
";
}
@@ -442,9 +442,10 @@ export default class MobileSelect {
} else {
const tempWheel = document.createElement("div");
tempWheel.className = "ms-wheel";
- tempWheel.innerHTML = `${this.getOptionsHtmlStr(
+ tempWheel.innerHTML = `${this.getOptionsHtmlStr(
this.displayJson[i]
)}
`;
+ tempWheel.setAttribute("data-index", i.toString());
this.wheels.appendChild(tempWheel);
}
}
@@ -688,11 +689,11 @@ export default class MobileSelect {
touch(event: TouchEvent | MouseEvent): void {
const path = event.composedPath && event.composedPath();
- const theSlider = path[1] as HTMLElement; // dom --> selectContainer
- if (!(theSlider as HTMLUListElement).hasAttribute("data-index")) return;
- const index = parseInt(
- (theSlider as HTMLUListElement).getAttribute("data-index") || "0"
- );
+ const currentCol = path.find((domItem) => {
+ return (domItem as HTMLElement).classList.contains("ms-wheel");
+ }) as HTMLElement;
+ const theSlider = currentCol.firstChild as HTMLElement; // ul.select-container
+ const index = parseInt(currentCol.getAttribute("data-index") || "0");
switch (event.type) {
case "touchstart":
case "mousedown":