摘自javascript基础教程

开始:

1.将脚本放在哪里:

1.1 放在html和<html>之间

范例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript</title>
<script type="text/javascript">
window.onload = writeMassage;
function writeMassage() {
document.getElementById("helloMessage").innerHTML = "hello world";
}
</script>
</head>

<body>
<h1 >
</h1>
</body>
</html>

1.2 放在标签之间

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript</title>
</head>
<body>
<h1 ;
</script>
</h1>
</body>
</html>

1.3 使用外部脚本

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript</title>
<script src="script01.js"></script>
</head>
<body>
<h1 >
</h1>
</body>
</html>

script.01.js写脚本

根据自己的需要选择

 

 

相关文章:

  • 2022-12-23
  • 2021-06-22
  • 2021-09-12
  • 2022-12-23
  • 2021-04-21
  • 2021-11-28
猜你喜欢
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-12-04
  • 2022-02-08
  • 2021-11-21
相关资源
相似解决方案