ios手机访问H5页面中$(document).on绑定无效问题

1.问题描述

用amazeUI做了个手机端网站,网站头部是一个点击按钮下拉菜单,点击页面其余区域下拉菜单隐藏。在chrome模拟安卓和iOS都可以正常触发,但是在真机实测的时候,iOS上面失效了。简单代码描述如下

    $(document).on("click", function (e) {
        $("#collapse-head").css("display", "none")
    });

function里面的代码不会执行。

 

2.解决

查阅信息后,说是iphone这些元素上没有click事件,它是touch事件

(1)有一个解决方法是给需要绑定事件的元素添加一个css cursor: pointer 。 
body{ 
cursor:pointer; 


(2)或者将click改为touchstart事件,或者共存 

  

$(document).on(“click touchstart”, “.name”, function() { 
    $("#collapse-head").css("display", "none")
});

 

posted @ 2018-01-15 17:13  Gabriel_wei  阅读(1304)  评论(0编辑  收藏  举报