在html中引入外部js文件,并调用js文件中的带参函数
1 项目结构
2 编写a.js、test.html
//a.js
function abc(str){
alert(str);
}
//test.html
<html>
<head>
<script type="text/javascript" src="a.js"></script>
<script type="text/javascript">
window.onload = function(){
var fun = abc; //引用abc函数
fun(123);
};
</script>
</head>
<body>
</body>
</html>3 测试结果
立即学习“前端免费学习笔记(深入)”;

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号