首页 > 移动平台 > 详细

IOS系统中点击失效

时间:2020-04-13 09:06:50      阅读:79      评论:0      收藏:0      [点我收藏+]

IOS系统中点击失效

问题

当委托给一个元素添加click事件时,如果事件是委托到 document 或 body 上,并且委托的元素是默认不可点击的(如 div, span 等),此时 click 事件会失效。
例如:

    //加载更多
    $(‘body‘).on(‘click‘,‘.showMoreData‘,function () {
    })

问题原因

React attaches event listeners to the document. iOS doesn‘t fire click events for nodes (at all) unless they seem "clickable"
Safari真的不希望你点击任何不是标签的东西。这是一个已知的问题:http : //stackoverflow.com/questions/5421659/html-label-command-doesnt-work-in-iphone-browser/6472181#6472181
大概意思就是ios不认为这个元素是可以点击的

解决办法

)
  • 把 click 改成 touchend 或 touchstart(注意加上preventDefault)
  • 将 click 元素委托到非 document 或 body 的父级元素上
  • 给目标元素加一条样式规则 cursor: pointer; (cursor: pointer; -webkit-tap-highlight-color: transparent;)
  • 我使用的是最后一种方法。省去了对IOS系统的判断。

    IOS系统中点击失效

    原文:https://www.cnblogs.com/cn-oldboy/p/12688999.html

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