javascript - 如何在桌面上显示时附加纯 jQuery 并在移动设备上显示时附加 jQuery Mobile?

标签 javascript jquery mobile jquery-mobile desktop

我正在构建一个网站,我想在移动设备上使用 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/

相关文章:

javascript - Jquery $(window).height() 函数不返回实际窗口高度

javascript - 移动设备上的视口(viewport)问题

javascript - 触摸事件 "touchstart"在 Mobile Safari 上返回错误位置。解决方法?

javascript - 从字典数组 JavaScript 中获取键的值

javascript - $().load() 不传递变量

javascript - $watchCollection 和多个表达式不起作用

jquery - 显示带有 url 的选项卡

Javascript,单击所有图像时打印消息

javascript - 为什么使用此功能拖动一个元素时两个元素都会移动?

javascript - 多级推送菜单,我设置了默认打开,移动端如何设置默认关闭?