慕田峪7331174
2019-02-13 16:00:31
<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觸發(fā),在手機(jī)端點(diǎn)擊時(shí)無法展開,發(fā)現(xiàn)是hover事件影響了,我該如何讓這段代碼在手機(jī)上不執(zhí)行,只在pc上執(zhí)行呢?
1 回答

森欄
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊
判斷客戶端是pc還是手機(jī)
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為手機(jī)端
添加回答
舉報(bào)
0/150
提交
取消