I'm new to Javascript and I'm trying to create a simple ElectronJS app. However, I can't get external scripts to work. It should be added that both files are in the same folder (as are all of the application files). What am I missing here?
This works:
main.html
<head>
<script>
function color_red() {
document.getElementById("collectBtn").style.color = "red";
}
</script>
</head>
<body>
<button id="collectBtn" onclick="color_red()">Color me!</button>
</body>
This does not:
connect.js
function color_red() {
document.getElementById("collectBtn").style.color = "red";
}
main.html
<head>
<script src="connect.js"></script>
</head>
<body>
<button id="collectBtn" onclick="color_red()">Color me!</button>
</body>
答案 0 :(得分:1)
正如@pergy所说,<script>
标签中可以包含内容,因此必须关闭才能正常工作。
<script src="connect.js"></script>
但是,如果您只是从Electron开始,我建议您看一下以下答案,以帮助您了解如何在应用程序中集成更好的函数调用: