【问题标题】:jQuery Click Event for 'body' not working on iOS'body' 的 jQuery Click 事件在 iOS 上不起作用
【发布时间】:2018-08-15 09:20:21
【问题描述】:

所以要让点击事件在 iOS 上工作,我知道它需要有 onClick=""cursor:pointer...

但是,我的点击事件在我的身体上(关闭菜单),那么如何在不让光标始终是指针的情况下解决这个问题?我尝试了@media screen,但这不起作用,因为如果有人有一台较小的计算机,它仍然始终有指针(我希望它适用于平板电脑)。

我尝试了<body onClick="">,但没有成功。

我的代码:

<pre>
  /* Open the sidenav */
  function openNav() {
    document.getElementById("mySidenav").style.width = "150px";
  }

  /* Close/hide the sidenav */
  function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
  }

  $('body').click(function(e){
    closeNav();
  });

  $('#mySidenav').click(function(e){
    openNav();
    e.stopPropagation();
  });

  $('.hamburger').click(function(e){
    openNav();
    e.stopPropagation();
  });
  </script>
</pre>

【问题讨论】:

    标签: jquery ios


    【解决方案1】:

    您应该能够检测到 iOS 设备,并且只在这些情况下设置 cursor: pointer

    var isiOS = (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false);
    if (isiOS) {
        $('body').css('cursor', 'pointer');
    }
    

    【讨论】:

      最近更新 更多