我已将代码缩减为以下内容:
<HTML> <head> <script src="https://AJAX.GoogleAPIs.com/AJAX/libs/jquery/1.6.4/jquery.min.Js"></script> <script> $(function() { $('#dynamic').click(function() {alert("works")}); $('#dynamic-with-onclick').click(function() {alert("works")}); $('#dynamic-with-dynamic-onclick').click(function() {alert("works")}).attr('onclick',''); }) </script> </head> <body> <ul> <li ID='static' onclick='alert("works")'>If there's an onclick it's called</li> <li ID='dynamic'>And if there's no onclick the iPad won't see other click events</li> <li ID='dynamic-with-onclick' onclick=''>But if there is one all events are called</li> <li ID='dynamic-with-dynamic-onclick'>And if we add one everything works</li> </ul> </body></HTML>
更新
现在看起来比10个月前我最初提出这个问题要简单得多;使用现代Mobile Safari,所有点击处理程序都会正常注册.所以,前进,只需使用$(…).click(function(){})!
解决方法 我们可以做Hackish事情,只需添加onclick到我们想要点击的任何东西.但 the “right” way to do this似乎正在使用适合iPad的活动:var hitEvent = 'ontouchstart' in document.documentElement ? 'touchstart' : 'click';$('#dynamic').bind(hitEvent,function() {alert("works")});$('#dynamic-with-onclick').bind(hitEvent,function() {alert("works")});$('#dynamic-with-dynamic-onclick').bind(hitEvent,function() {alert("works")}).attr('onclick','');
另一种方法是到bind to multiple events,并对任何一个被调用的人感到满意.
我目前正在使用第一个解决方案;我可能会尝试另一个,因为我觉得它更干净.
总结以上是内存溢出为你收集整理的在iPad上没有调用jQuery单击处理程序全部内容,希望文章能够帮你解决在iPad上没有调用jQuery单击处理程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)