html和js结合方式

两种方式:
内部js、外部js

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js和html的两种结合方式</title>
</head>
<body>

<!--方式1 内部js-->
<script type="text/javascript">
    // 直接在<script>标签内写js代码
    alert(123)
</script>

<!--方式2 外部js,即从外部引入一个js文件
此时script标签中间不要再写js代码,因为写了也不会执行。
-->
<script src="1.js">
</script>
789
</body>
</html>

外部js文件:1.js

alert(456)

猜你喜欢

转载自blog.csdn.net/weixin_44072535/article/details/110917651
今日推荐