大佬教程收集整理的这篇文章主要介绍了javascript – 仅为移动设备加载JQuery Mobile脚本,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<head> <title>Page title</title> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" /> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> </head>
并在页面的body元素中使用数据角色属性来显示东西.
这些页面在移动设备上看起来相当不错,但即使请求来自非移动浏览器,它也以类似的方式看起来.
我想知道如果有人知道一个方法来加载JQuery Mobile脚本,只有当请求来自移动设备.
迄今为止我所尝试的是使用一个检测我的用户代理的函数,如果它是移动设备,则加载该脚本:
function init() { if(isMobile()) { document.write('<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />'); document.write('<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>'); dcument.write('<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>'); } } function isMobile() { if(navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/iPhone|iPad|iPod/i) || navigator.userAgent.match(/IEMobile/i)) return true; return false; }
>使用脚本从http://detectmobilebrowsers.com/检测
>使用http://yepnopejs.com/测试
像这样(应该适用于jQuery脚本从http://detectmobilebrowsers.com/):
yepnope({ test : jQuery.browser.mobile,yep : 'mobile_specific.js',nope : ['normal.js','blah.js'] });
编辑:
另请参阅https://github.com/borismus/device.js,根据条件加载内容.我不确定它是否允许您加载条件JS文件.
以上是大佬教程为你收集整理的javascript – 仅为移动设备加载JQuery Mobile脚本全部内容,希望文章能够帮你解决javascript – 仅为移动设备加载JQuery Mobile脚本所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。