如何使用变量自动运行外部JavaScript函数?
当页面加载时,我尝试运行一个外部javascript函数,该函数接受一个变量,我只能通过调用javascript函数的页面 HTML页面如何使用变量自动运行外部JavaScript函数?,javascript,jquery,html,Javascript,Jquery,Html,当页面加载时,我尝试运行一个外部javascript函数,该函数接受一个变量,我只能通过调用javascript函数的页面 HTML页面 <head> <script src="path/to/file.js" type="text/javscript> window.onload = function() { doFunction(variable); } </script> </head> 由于您没有异步加载文件.js,因此可以在头中包含
<head>
<script src="path/to/file.js" type="text/javscript>
window.onload = function() {
doFunction(variable);
}
</script>
</head>
由于您没有异步加载文件.js
,因此可以在头中包含脚本。只要在加载脚本后调用该函数,它就会正常工作
<html>
<head>
<script src="path/to/file.js" type="text/javscript>
</head>
<body>
<script type="text/javascript">
window.onload = function() {
doFunction('someVal');
};
</script>
</body>
</html>
由于您没有异步加载文件.js
,因此可以在头中包含脚本。只要在加载脚本后调用该函数,它就会正常工作
<html>
<head>
<script src="path/to/file.js" type="text/javscript>
</head>
<body>
<script type="text/javascript">
window.onload = function() {
doFunction('someVal');
};
</script>
</body>
</html>
每个
元素可以有src
或内联代码,而不是两者都在一个元素中。将内联代码移动到第二个
元素@JonathanLonowski我会做一个window.onload(doFunction(variable));?如果我正在使用src@JonathanLonowski如何操作?在当前的
之后添加第二个
元素。将内联JavaScript移入其中。@JonathanLonowski您解决了它!每个
元素可以有src
或内联代码,而不是两者都在一个元素中。将内联代码移动到第二个
元素@JonathanLonowski我会做一个window.onload(doFunction(variable));?如果我正在使用src@JonathanLonowski如何操作?在当前的
之后添加第二个
元素。将内联JavaScript移入其中。@JonathanLonowski您解决了它!
<html>
<head>
<script src="path/to/file.js" type="text/javscript>
</head>
<body>
<script type="text/javascript">
window.onload = function() {
doFunction('someVal');
};
</script>
</body>
</html>