<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上执行呢?
1 回答
森栏
TA贡献1810条经验 获得超5个赞
判断客户端是pc还是手机
function IsPC() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone",
"SymbianOS", "Windows Phone",
"iPad", "iPod"];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
var flag = IsPC(); //true为PC端,false为手机端
添加回答
举报
0/150
提交
取消