【问题标题】:jquery js and jquery mobile js not workingjquery js和jquery mobile js不工作
【发布时间】:2018-04-15 19:47:18
【问题描述】:

我正在使用带有 atom 编辑器的 phonegap,但我的 jquery 和 jquery mobile 无法正常工作。所有 .js 文件都在一个名为 js 的文件夹中,并且根目录已正确链接。我已经尝试了在线 code.jquery.com 版本,但它仍然无法正常工作。这些是我尝试过的 2 个版本:

版本 1

 `<link rel="styleheet" type="text/css" href="css/jquery.mobile-
 1.4.5.min.css">
 <link rel="styleheet" type="text/css" href="css/jquery.mobile-1.4.5.css">
 <link rel="stylesheet" type="text/css" href="css/index.css" />
 <script type="text/javascript" src="cordova.js"></script>
 <script type="text/javascript" src="js/index.js"></script>
 <script type="text/javascript"> app.initialize();</script>
 <script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js">
 </script>
 <script type="text/javascript" src="js/jquery.mobile-1.4.5.js"></script>
 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
  `

版本2

 <link rel="stylesheet" 
  href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"/>
  <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-
   1.4.5.min.js"></script>
  <script
   src="https://code.jquery.com/jquery-3.2.1.min.js"
   integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
   crossorigin="anonymous"></script>
   <link rel="stylesheet" type="text/css" href="css/index.css" />
   <script type="text/javascript" src="cordova.js"></script>
  <script type="text/javascript" src="js/index.js"></script>
   <script type="text/javascript">app.initialize();</script>

我使用这段代码来测试我的 jquery 是否正常工作

   `<script>
 window.onload = function(){
  if (window.jquery){
    alert("YES");
  }else {
    alert("ERROR");
  }
 }
  </script>
   `

而且每次都出现错误。我编程并没有出现 YES ERROR:

【问题讨论】:

标签: jquery cordova jquery-mobile atom-editor phonegap


【解决方案1】:

用于测试 Jquery 是否为 Load 使用,如下所示:

<script>
     window.onload = function(){
      if (jQuery) {
        alert("jquery is loaded");
       } else {
        alert("Not loaded");
        }
     }
  </script>

【讨论】:

    【解决方案2】:

    jQuery 和 jQuery mobile 无法在您的项目中运行,因为 jQuery mobile 1.4.5 版不支持 jQuery 3.x 版。

    尝试在您的应用程序中使用 jQuery 版本 2.x,看看这是否能解决问题。为了快速测试这一点,您可以使用 Google 托管的 jQuery 来确保在下载所有文件之前:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    

    jQuery mobile 1.5.0 于今年 5 月发布,实际上支持 jQuery 3.x。切换到新版本的 jQuery mobile 也可以解决问题,但请记住 1.5.0 是 Alpha 版本。你可以阅读更多关于jQuery mobile的最新版本here

    【讨论】:

      【解决方案3】:

      浏览器控制台错误是什么样的?通过右键单击页面 > 检查元素 > 控制台来到达那里

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-09
        • 1970-01-01
        相关资源
        最近更新 更多