关于on点击事件在IOS中失效的问题

作者Veris 文章分类 分类:Javascript 文章评论 0条评论 阅读次数 已被围观 2143

这个是关于使用

$(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‘)})


分类:Javascript
标签: on
【上一篇】移动交互大屏项目总结
【下一篇】党的基础知识

发表评论: