有两种方式:
1.通过<script>标签嵌入到HTML页面中;
2.可以保存为扩展名为.js的文件后,通过<script>标记引入到网页中。
index.html
| <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="java.js"></script> </head> <body> <input type="button" value="click me" onclick="fun_a()"/> </body> </html> |
java.js
| function fun_a() { alert("a"); } |
本文将介绍如何在HTML页面中通过<script>标签和外部.js文件嵌入JavaScript代码,实现基本的网页交互功能,如弹窗提示。示例代码包括创建按钮元素并设置点击事件,调用函数执行特定操作。
2826

被折叠的 条评论
为什么被折叠?



