我有以下问题我有一个
<ul>
<li>
<a href="/">main page</a>
</li>
</ul>
这将适用于任何桌面浏览器,但不会点击 Ipad/Iphone 和 Android。
最佳答案
此问题与您提到的设备(Ipad/Iphone、android 手机)有关。 touchend 事件调用 event.stopPropagation() 因为您无法实现该操作。 要解决您的问题,您有 2 个解决方案: - 不要把你的代码放在里面
<ul> and <li> and the code will be like that
<div>
<a href="/"> main page</a>
</div>
-第二种解决方案创建一个名为 eventStop 的新指令
<ul>
<li>
<a href="/" stop-event="touchend">main page</a>
</li>
</ul>
指令是
.directive('stopEvent', function() {
return {
restrict: 'A',
link: function(scope, element, attr) {
element.on(attr.stopEvent, function(e) {
e.stopPropagation();
});
}
};
});
关于javascript - 单击在移动浏览器上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32452927/