简体   繁体   English

从外部javascript调用html文档中的函数?

[英]Call a function in html document from external javascript?

如何从外部javascript文件中调用html文档中的函数?

When the external javascript is included in the page it has access to every function on the page as well as functions in other JS files included on the page. 当页面中包含外部javascript时,它可以访问页面上的所有功能以及页面中包含的其他JS文件中的功能。

This is assuming none of the functions are wrapped in a namespace... 这是假设所有函数都没有包装在名称空间中...

Javascript file: Javascript文件:

 function functionName()
    {
    some code to be executed
    }

Html: HTML:

<!DOCTYPE html>
<html>
<head>
</head>

<body>
<button onclick="functionName()">Try it</button>
</body>
</html>

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

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