jQuery和jQuery Mobile不起作用

3
我正在使用Atom编辑器和PhoneGap,但我的jQuery和jQuery Mobile无法正常工作。所有.js文件都在名为js的文件夹中,并且根目录链接正确。我尝试了在线的code.jquery.com版本,但仍然无法工作。这是我尝试过的两个版本:

版本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>
   `

每次都出现错误。我进行编程,从未出现过错误。

enter image description here


可能是代码中要提到的jQuery版本是什么的重复。 - deblocker
3个回答

3

测试是否已经加载了 Jquery,可以使用以下方式:

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

2

由于jQuery mobile版本1.4.5不支持jQuery版本3.x,所以在您的项目中无法使用jQuery和jQuery mobile。

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

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

今年5月发布了jQuery mobile 1.5.0版本,该版本支持jQuery 3.x。升级到新版本的jQuery mobile可能是一个解决方法,但请记住,1.5.0版本是Alpha版本。您可以在此处阅读有关最新版本的jQuery mobile的更多信息


0

浏览器控制台错误是什么样子的?通过右键单击页面>检查元素>控制台进入。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接