Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
电子存储javascript函数_Javascript_Electron - Fatal编程技术网

电子存储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();
});