猿问

响应式网站在pc上给一个元素定义了hover事件,在手机端点击的时候被触发了?

<div class="dropdown">

  <a data-toggle="dropdown" href="#">xxx</a>

  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">

    ...

  </ul>

</div>

$('.dropdown').hover(function() {

   $(this).hasClass('open');

},function(){

   $(this).removeClass('open');

})

把boostrap的dropdown插件改成hover触发,在手机端点击时无法展开,发现是hover事件影响了,我该如何让这段代码在手机上不执行,只在pc上执行呢?

慕田峪7331174
浏览 1165回答 1
1回答

森栏

判断客户端是pc还是手机function IsPC() {&nbsp; &nbsp; var userAgentInfo = navigator.userAgent;&nbsp; &nbsp; var Agents = ["Android", "iPhone",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "SymbianOS", "Windows Phone",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "iPad", "iPod"];&nbsp; &nbsp; var flag = true;&nbsp; &nbsp; for (var v = 0; v < Agents.length; v++) {&nbsp; &nbsp; &nbsp; &nbsp; if (userAgentInfo.indexOf(Agents[v]) > 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flag = false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; return flag;}&nbsp;var flag = IsPC(); //true为PC端,false为手机端
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答