Electron使用中遇到的問題

1.引入jquery和bootstrap的時候報錯 Uncaught Error: Bootstrap's JavaScript requires jQuery  或者 Uncaught ReferenceError: $ is not definedcss

解決方案:底層是由於node和jquery衝突了。這裏只說解決方法,在index.html中引入jquery和bootstrap前先引入下列代碼html

    <script>
      window.nodeRequire = require;
      delete window.require;
      delete window.exports;
      delete window.module;
    </script>

最終結果代碼以下,就能夠正常運行操做jquery等了node

<html>
  <head>
    <meta charset="UTF-8">
    <title>Hello World!</title>
    <link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <h1 id="hh">這樣就能夠啦</h1>
    <!-- All of the Node.js APIs are available in this renderer process. -->
    We are using Node.js <script>document.write(process.versions.node)</script>,
    Chromium <script>document.write(process.versions.chrome)</script>,
    and Electron <script>document.write(process.versions.electron)</script>.
    <script>
      window.nodeRequire = require;
      delete window.require;
      delete window.exports;
      delete window.module;
    </script>
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="./renderer.js">
       console.log($('#hh').text());
    </script>
  </body>
</html>
相關文章
相關標籤/搜索