[英]Call a JavaScript function before declaration
I have this function inside test.js
:我在
test.js
有这个函数:
function testing(){
document.write("<p>Tes1</p>");
}
And then a basic HTML page.然后是一个基本的 HTML 页面。
Is it possible to call the function before being declared and add this to the page?是否可以在声明之前调用该函数并将其添加到页面中?
<p>Test1</p>
Because if I include the test.js
at the bottom of the page, it's not working.因为如果我在页面底部包含
test.js
,它就不起作用。 Is there a way to make it work (with a JavaScript file being included at the bottom of the HTML page)?有没有办法让它工作(在 HTML 页面底部包含一个 JavaScript 文件)?
把你的testing()
函数调用放在window.onload
回调中,就像这样,
window.onload = function(){ testing(); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.