javascript基础教程学习总结(1)

摘自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 id="helloMessage">
</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 id="helloMessage">
<script>
document.getElementById("helloMessage").innerHTML = "hello world";
</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 id="helloMessage">
</h1>
</body>
</html>

script.01.js写脚本

根据自己的需要选择

 

 

posted @ 2013-07-09 10:17  追梦的超哥  阅读(232)  评论(0编辑  收藏  举报