Electron使用中遇到的问题
1.引入jquery和bootstrap的时候报错 Uncaught Error: Bootstrap's JavaScript requires jQuery 或者 Uncaught ReferenceError: $ is not defined
解决方案:底层是因为node和jquery冲突了。这里只说解决方法,在index.html中引入jquery和bootstrap前先引入下列代码
<script> window.nodeRequire = require; delete window.require; delete window.exports; delete window.module; </script>
最终结果代码如下,就可以正常运行操作jquery等了
<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>

浙公网安备 33010602011771号