JavaScript——引入JavaScript

 

1.内部标签

1 <script>
2       alert('hello world!')
3       ....
4 </script>

 

2.外部引入

      xxx.js

alert('hello world!')

     xxx.html

 <script src="js/xxx.js"></script>

 

测试代码

    

html代码

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 
 7 <!--内部标签-->
 8      <!--script标签内写Javascript代码   -->
 9      <!--    <script>-->
10      <!--        alert('hello world!')-->
11      <!--    </script>-->
12 
13 
14 <!--外部引入-->
15      <!--注意:script标签必须成对出现-->
16     <script src="js/qj.js"></script>
17 
18      <!--不要显示定义type,也默认就是javascript-->
19     <script type="text/javascript">
20 
21     </script>
22 
23 </head>
24 <body>
25 
26 
27 <!--这里也可以存放-->
28 </body>
29 </html>

 

js代码

1 alert('嘿嘿,你好啊!')

 

posted @ 2021-04-22 19:07  cengxuyuan  阅读(184)  评论(0)    收藏  举报