此功能在IE,Firefox和Chrome上完美运行,但在iPhone上,只有在点击时才能使用<img>.点击页面(在img上的任何地方)都不会触发事件.
$(document).ready(function () {
$(document).click(function (e) {
fire(e);
});
});
function fire(e) { alert('hi'); }
Run Code Online (Sandbox Code Playgroud)
HTML部分非常基础,不应该是一个问题.
有任何想法吗?
我有一个使用jQuery和大量动态生成内容的项目.click左上角元素上有一个处理程序 - "主动"得分 - 它在桌面Safari上工作正常但在Mobile Safari上根本没有调用; 灰色覆盖层永远不会出现,也不会采取任何措施.与点击区域(右侧172)的点击处理程序和状态(底部的"添加状态效果";确认;它出现在肖像上)的情况相同:所有工作都在桌面上但不是移动Safari.
我已将代码缩减为以下内容:
<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>
Run Code Online (Sandbox Code Playgroud)
现在看起来比我10个月前最初提出这个问题要简单得多; 使用现代Mobile Safari,所有点击处理程序都会正常注册.所以,出去,只是使用$(...).click(function() {})!