1

我有一个触发touchStart事件的 div:

<div class="button" ontouchstart="touchStart(event)"> button</div>

当我的手指落在 div 内的文本按钮上时,事件不会被触发,div 事件表面上的其他任何地方都会被触发,当我触摸文本时如何让它触发?

4

2 回答 2

1

如果您知道 div 的大小,那么您可以使用 ontouchstart 事件在文本上方添加一个透明 div。

<div class="buttoncontainer">
    <div class="button"> button</div>
    <div  ontouchstart="touchStart(event)" class="somethingrelative"></div>
</div>

其中按钮容器和相关的东西有助于定位。

于 2011-08-01T15:45:18.733 回答
0

您还可以将文本放在另一个元素中,例如跨度,并使其对事件无反应:

.button span {  
    pointer-events: none;
}
于 2013-05-24T09:51:05.080 回答