简体   繁体   中英

Ons navigation (onsen UI), use of javascript code

When I use the standard technique ons-navigation, the javascript code on the ons-page does not execute. Does anyone know what I do wrong?

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-  scalable=no">
  <script src="components/loader.js"></script>
    <link rel="stylesheet" href="components/loader.css">
    <link rel="stylesheet" href="css/style.css">
  <script>
     ons.bootstrap();
     ons.disableAutoStatusBarFill();  // (Monaca enables StatusBar plugin by default)
  </script>
</head>
<body>
  <ons-navigator var="myNavigator" page="login.html">
  </ons-navigator> 
</body>
</html>

And here is the login.html:

<ons-page>

<script>
  console.log("test11");   
</script>

</ons-page>

The reason why it's not working is that the browser won't execute script tags that are added through replacing el.innerHTML , which is what Onsen does when you push a page.

Please see this question for why it's not working: Can scripts be inserted with innerHTML?

You shouldn't use inline script tags mixed in your HTML. Please look up how to structure you're JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM