jQuery works in browser, but not in an android emulator

本秂侑毒 提交于 2019-12-12 01:15:02

问题


I'm a noob in hybrid development and I'm trying to use jQuery in my App.

I'm surprised that the my code is working fine in the browser, but not in an android emulator and I don't quite understand the reason for that.

Here is my code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"> 
<link rel="stylesheet" type="text/css" href="css/onsenui.css">
<link rel="stylesheet" type="text/css" href="css/onsen-css-  
  components.css">
<link rel="stylesheet" type="text/css" href="css/sliding_menu.css">
<link rel="stylesheet" type="text/css" href="css/index.css"> 
<script type="text/javascript" src="js/jquery/dist/jquery.min.js"> 
</script>  
<script type="text/javascript" src="js/angular/angular.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/onsenui.min.js"></script>
<script type="text/javascript" src="js/angular-onsenui.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>   

</head>
<script>
   $(document).ready(function(){
      $("h6").click(function(){
       $(this).hide();
     });
   });
</script> 
<body>

<h6>If you click on me, I will disappear.</h6>
<h6>Click me away!</h6>
<h6>Click me too!</h6>

</body>
</html> 

Logs Output :

Cant understand what may be the reason...


回答1:


Please try removing all the js and set only jQuery js may be they were conflicted But it is working fine with your browser so here is a jsFiddle Demo, check and compare

<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<body>
 <h6>If you click on me, I will disappear.</h6>
 <h6>Click me away!</h6>
 <h6>Click me too!</h6>
</body>

<script>
$(document).ready(function(){
  $("h6").click(function(){
   $(this).hide();
 });
});
</script>



回答2:


Use chrome://inspect/#devices and open the inspector for your APP.

Then find if the jquery.min.js file exists in Sources,

Type $("h6").hide(); in console and execute it, check does it work or is there any error in console?



来源:https://stackoverflow.com/questions/36932137/jquery-works-in-browser-but-not-in-an-android-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!