单击时的jQuery在iPhone(触摸设备)上不起作用 [英] jQuery on click not working on iPhone (touch devices)
本文介绍了单击时的jQuery在iPhone(触摸设备)上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以向我解释为什么它可以在浏览器中运行,但不能在苹果iPhone等移动设备上运行.在iPhone上,我从未从警报中得到hello
.为什么?
Can anyone please explain to me why this is working in the browser but not on mobile devices like Apple's iPhone. On iPhone, I never get the hello
from the alert. Why?
<div class="close">
Click here
</div>
JS:
$(document).on('click', '.close', function() {
alert('hello');
});
此处为示例: https://jsfiddle.net/27ezjrqr/5/
推荐答案
默认情况下,div不是可点击的"元素.但是添加cursor: pointer;
会使iOS将其视为可点击的.
By default, divs are not a "clickable" elements. But adding cursor: pointer;
makes iOS treat it as clickable.
所以您要做的就是添加
.close {
cursor: pointer;
}
添加到您的CSS,然后它将正常工作.
to your CSS and then it will work.
此处证明: https://jsfiddle.net/27ezjrqr/6/
$(document).on('click', '.close', function() {
alert('hello');
});
.close {
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="close">
Click here
</div>
这篇关于单击时的jQuery在iPhone(触摸设备)上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文