首页 > 移动平台 > 详细

Jquery 在ios上事件委托失效

时间:2018-08-30 11:30:53      阅读:186      评论:0      收藏:0      [点我收藏+]

点击通过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上事件委托失效

原文:https://www.cnblogs.com/rachelch/p/9559094.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!