采纳哦
外联js:
index.html中的代码
<!DOCTYPE html><html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="print.js"></script>
</head>
<body onload="print()">
</body>
</html>
print.js中的代码
function print() {alert("我是外联js")
}
代码结构
运行结果:
改为内联js
index.html中的代码:
<!DOCTYPE html><html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body onload="print()">
</body>
<script>
function print() {
alert("我是内联js")
}
</script>
</html>
运行结果: