js-入门(引入方式)

在html中引入js的两种方法:

1、页面内嵌<script></script>

2、外部引入<script src="location"></script>

为符合web标准(w3c标准中的一项)结构、样式、行为相分离,通常会采用外部引入

<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>js引入方式</title>
</head>
<body>
  <script type="text/javascript">
     document.write('hello world');
  </script>
</body>
</html>

<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>js引入方式2</title>
</head>
<body>
  <script type="text/javascript" src="hello.js">
  </script>
</body>
</html>
/*.新建一个hello.js文件..................................................................*/

     document.write('hello world');

两种方法不可以同时使用,若既引用了外部标签又再内部写了内容,则内部内容失效

猜你喜欢

转载自blog.csdn.net/qq_37503890/article/details/88085491