我正在用 ElectronJS 编写一些 HTML 代码。我需要在 HTML 中使用 JQuery,所以我用 npm install jquery
安装了 JQuery .
但是我应该导入什么文件才能使用 JQuery?
<!DOCTYPE html>
<html lang="en">
<head>
<script src="??"></script>
<script>
$(document).keydown(function(event) {
alert(event.which)
})
</script>
</head>
<body>
foobar
</body>
</html>
在<script src="??">
我应该写什么?
(抱歉英语不好)
最佳答案
就放<script src="node_modules/jquery/dist/jquery.min.js"></script>
在你的 html 中。
注意:为了让你的脚本在 electron 上执行,你需要在你的 html 中写如下:
<script>
if (typeof module === 'object') {
window.module = module;
module = undefined;
}
</script>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script>
$(document).keydown(function(event) {
alert(event.which)
})
</script>
//Put your other scripts here
<script>
if (window.module) module = window.module;
</script>
关于javascript - 使用 Electron 在 HTML 中导入 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57591204/