电子存储javascript函数
我已经创建了一个新的电子应用程序 它由以下文件组成:电子存储javascript函数,javascript,electron,Javascript,Electron,我已经创建了一个新的电子应用程序 它由以下文件组成: index.html main.js renderer.js 在index.html中,我添加了一个带有onclick事件的按钮: <button onclick="myfunction()">Call Function</button> 我的问题是,我已经将函数代码添加到renderer.js和main.js的底部,当我单击按钮时,我没有看到任何警报 如何从index.html调用js函数?让myFunction
index.html
main.js
renderer.js
在index.html中,我添加了一个带有onclick事件的按钮:
<button onclick="myfunction()">Call Function</button>
我的问题是,我已经将函数代码添加到renderer.js和main.js的底部,当我单击按钮时,我没有看到任何警报
如何从index.html调用js函数?让myFunction驻留在单独的javascript文件中。假设它名为“functions.js”。要在HTML文件(index.HTML)中使用此函数,只需按以下方式使用标记添加Javascript代码-
<html>
<body>
...
</body>
<script type="text/javascript" src="./functions.js"></script>
</html>
你应该在
document.ready
之外添加myfunction
如果你正在使用它,你是说在main.js中添加app.on('ready',createWindow)?
<html>
<body>
...
</body>
<script type="text/javascript" src="./functions.js"></script>
</html>
document.getElementById('btn').addEventListener("click", function(){
myFunction();
});