如何在 iPhone Web 应用程序中使用 jQuery 进行单击事件 [英] How do I use jQuery for click event in iPhone web application
问题描述
当我将 jQuery 用于简单的点击事件时,它仅适用于链接.有没有办法让它适用于跨度等:
When I use jQuery for a simple click event it only works for links. Is there a way to make it work for spans etc:
$("span.clicked").live("click", function(e){alert("span clicked!")});
$("a.clicked").live("click", function(e){alert("link clicked!")});
SPAN 在 Safari 中有效,但在 Mobile Safari 中无效(在 iPhone 或 iPad 上),而 A 标签在两者中都有效.
The SPAN works in Safari but not Mobile Safari (on iPhone or iPad) whereas the A tag works in both.
推荐答案
我也遇到了这个问题.在反复琢磨并试图找出问题之后,我找到了一个简单的解决方案.
I struggled with this as well. After lots of toying around and trying to figure out the problem, I came across a simple solution.
如果您将元素的cursor
设置为pointer
,它会再次神奇地与Jquery 的live 和click 事件一起工作.这可以在 CSS 中全局设置.
If you set the element's cursor
to pointer
, it magically works again with Jquery's live and the click event. This can just be set globally in the CSS.
这篇关于如何在 iPhone Web 应用程序中使用 jQuery 进行单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!