您好我已经给了代码
$('.active').hide()
我想在我使用手机时运行此代码,当我使用桌面时,我不想运行此代码。请指导如何解决这个问题。
答案 0 :(得分:1)
尝试时在代码中添加以下行:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mobile-detect/1.3.0/mobile-detect.min.js"></script>
var deviceType = "";
var md = new MobileDetect(window.navigator.userAgent);
if (md.tablet())
deviceType = "tablet";
else if (md.phone()){
deviceType = "phone";
}
else
deviceType = "desktop";
if(deviceType=="phone"){
$('.active').hide();
}