最族
关于on点击事件在IOS中失效的问题
2018-10-20 Veris


这个是关于使用



$(document).on(‘click‘,selector,function)



在移动端ios中使用on点击事件无效的解决办法



1.将selector元素增加样式cursor:pointer(全场最佳解决方案)




<style>
    .a{width:100px;height:100px;background:red}
    .b{width:10px;height:10px;cursor:pointer}
</style>
<div class="a">
<div class="b">
</div>
</div>
<script>$(document).on(‘click‘,‘.b‘,function(){console.log(‘22222‘)})</script>


2.将click换成touchstart(在移动端基本都用吧)




$(document).on("touchstart",function(){console.log(‘22222‘)})






3.将document换成selector元素的父级元素


$(".a").on(‘click‘,".b",function(){console.log(‘22222‘)})




发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容