Jquery 在ios上事件委托失效

Posted rachelch

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jquery 在ios上事件委托失效相关的知识,希望对你有一定的参考价值。

点击通过js遍历出来的列表,跳转页面。点击事件委托在document上,

像这样: $(document).on("click",".nav",function(){  })

在web和android上度没问题,能够正常跳转。但是在ios上点击没有任何反应。原因是:ios上事件委托不能绑定在document和ios上,应该绑定在它的其它父级元素上

        $.each(dataall,function(i,item){
              str += ‘<div class="nav shadow-black" data-str="‘
              +item.data_str
              +‘"><div class="nav-item"><img src="‘
              +item.myheadimgurl
              +‘"  /><div class="ellipsis">‘
              +item.myusername
              +‘</div></div><div class="nav-item alike"><div>VS</div><div>‘
              +item.addtime
              +‘</div></div><div class="nav-item"><img src="‘
              +item.compareheadimgurl
              +‘"  /><div class="ellipsis">‘
              +item.compareusername
              +‘</div></div></div>‘;
            });    
            $("#shareContent").html(str);
//ios点击没反应,未触发事件
$(document).on(‘click‘,‘.nav‘,function(){
    var data_str = $(this).data(‘str‘);
    window.location.href = ‘http://test.epoque.cn/user/footcompare/compare_foot?data_str=‘+ data_str;
})

//将事件委托在其他元素上,ios点击可跳转
$(‘#shareContent‘).on(‘click‘,‘.nav‘,function(){
    var data_str = $(this).data(‘str‘);
    window.location.href = ‘http://test.epoque.cn/user/footcompare/compare_foot?data_str=‘+ data_str;
})

 

另外一个问题:经常在ios上一个按钮点不了,像这样<span>按钮</span>,原因是语义化的问题,可以用a标签或者button,解决办法:加样式:cursor:pointer。

 

以上是关于Jquery 在ios上事件委托失效的主要内容,如果未能解决你的问题,请参考以下文章

jQuery代码优化:事件委托

ios点击事件失效

Jquery事件委托之Safari

原生js如何绑定a连接点击事件?

jQuery事件委托

在微信公众号开发(微站)过程中用Zepto/jquery的on/live绑定的click事件点击无效(不能执行)