想问一下,JavaScript脚本何时会得到执行。必须要调用的时候吗?比如说我写了如下测试程序
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script language="JavaScript">
function test(){
document.bgColor="black" //注意该两句代码的位置
document.fgColor="blue"
}
</script>
</head>
<body onload="test()">
测试document对象的属性
</body>
</html>
如果换成如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script language="JavaScript">
document.bgColor="black" //注意该两句代码的位置
document.fgColor="blue"
function test(){
}
</script>
</head>
<body onload="test()">
测试document对象的属性
</body>
</html>
则document.bgColor="black"
document.fgColor="blue"
两句得不到执行
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script language="JavaScript">
function test(){
document.bgColor="black" //注意该两句代码的位置
document.fgColor="blue"
}
</script>
</head>
<body onload="test()">
测试document对象的属性
</body>
</html>
如果换成如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script language="JavaScript">
document.bgColor="black" //注意该两句代码的位置
document.fgColor="blue"
function test(){
}
</script>
</head>
<body onload="test()">
测试document对象的属性
</body>
</html>
则document.bgColor="black"
document.fgColor="blue"
两句得不到执行
document.bgColor="black" //注意该两句代码的位置
document.fgColor="blue"
function test(){
}
</script>
放到</body>后面
document.fgColor="blue"
这两句该有个';'结束符吧
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script language="JavaScript">
document.bgColor="black" //注意该两句代码的位置
document.fgColor="blue"
function test(){
}
</script>
</head>
<body onload="test()">
测试document对象的属性
</body>
</html>