jQuery works in browser, but not in an android emu

2019-09-16 06:04发布

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 :

enter image description here

Cant understand what may be the reason...

2条回答
叼着烟拽天下
2楼-- · 2019-09-16 06:53

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>
查看更多
对你真心纯属浪费
3楼-- · 2019-09-16 06:54

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?

查看更多
登录 后发表回答