我只是使用 mootools 创建一个点击事件,如下所示:
$$('body').addEvent('click:relay(div.smart-bg)', function(){
xxxxxxxxxxx
});
但是,这似乎不会在 iPad 上触发(而其他点击事件会触发)。这与它是添加的动态元素并且我正在使用 :relay 的事实有关吗?
非常感谢任何指点。
广告。
最佳答案
当我在 div
上添加委托(delegate)点击事件时,我遇到了类似的问题。
This article from quirksmode可能有帮助:
There must be a reason for this behaviour. I don’t know what that reason is, but currently I think that it’s a memory management problem. Apparently, making all elements on a page clickable demands too many resources, and the Apple engineers decided to disable it.
还有...
Fortunately it’s pretty easy to solve: you have to make the element clickable by giving it an onclick event handler of its very own. That handler can be empty; as long as it’s present it will make any element clickable.
也许在你的情况下......
$$('.smart-bg').each(function(el) {
el.onclick = function() {};
});
当然,鉴于它是委托(delegate)事件,您必须确保在动态创建的每个 .smart-bg
元素上重新创建 onclick 处理程序。
关于javascript - mootools点击:relay not firing on ipad/iphone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12213944/