我正在构建一个网站,我想在移动设备上使用 jQuery Mobile 执行 javascript,但由于并非所有桌面浏览器都支持 jQuery Mobile,但我希望附加普通的 jQuery。我该怎么做?
最佳答案
这是在客户端执行此操作的一种方法:
<html>
<head>
<script type="text/javascript">
function isMobileDevice() {
var index = navigator.appVersion.indexOf("Mobile");
return (index > -1);
}
function loadJQuery() {
if(isMobileDevice())
document.write("<script type='text/javacript src='"+path_to_mobile_jquery+"'></script>");
else
document.write("<script type='text/javacript src='"+path_to_normal_jquery+"'></script>");
}
</script>
</head>
<body onload="loadJQuery();">
<!-- Content -->
</body>
</html>
关于javascript - 如何在桌面上显示时附加纯 jQuery 并在移动设备上显示时附加 jQuery Mobile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6868617/