javascript - 使用 Electron 在 HTML 中导入 JQuery
问题描述
我正在用 ElectronJS 编写一些 HTML 代码。我需要在 HTML 中使用 JQuery,所以我用npm install 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。
注意:为了让您的脚本在电子上执行,您需要在 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>
推荐阅读
- mongodb - 如何将字段描述添加到 mongodb 集合
- visual-studio-code - VS 代码扩展:将文本附加到文档的末尾
- django - 如何在 Django 博客应用程序中插入多个图像?
- list - Flutter/Dart - 关于如何对未来进行故障排除的建议?
- javascript - 突变观察者中的字符数据未按预期工作
- python - 通过拖放将数据添加到 QTreeWidget
- ruby-on-rails - 在反向代理下设计 rails 6
- java - 如何将 \" 转义为绝对的、具体的、唯一的、单一的值?Java
- python - 如何更改此嵌套列表中的所有值?
- javascript - 未捕获的类型错误:无法在 rating.js:4 处读取 null 的属性“长度”