简体   繁体   English

如何从a.HTML文件调用JavaScript function到a.JS文件?

[英]How to call JavaScript function from a .HTML file to a .JS file?

I've been working on a.js and.html file and in my.js file, I want to call to a function that's located in the.html file.我一直在研究 a.js 和 .html 文件,在 my.js 文件中,我想调用位于 .html 文件中的 function。

This is the function in the.html file that I want to be called to:这是我想要调用的.html文件中的function:

    <script>
        function themeChange4() {
            document.getElementById("theStyle").style = "";
        }
    </script>

This is where I want the function to be called to in my.js file:这是我希望在 my.js 文件中调用 function 的地方:

add_icon_not_via_filesystem({
    title: "Vending Machine",
    icon: "Soda",
    open: themeChange4,
});

If I understood You want from HTML如果我理解你想要 HTML

  <script src="js.js"></script>
  <script>
  function themeChange4(){
     add_icon_not_via_filesystem(); 
  }
themeChange4();
 </script>

to call打电话

function add_icon_not_via_filesystem(){
 alert('This');
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM