我是javascript的新手,并尝试执行以下代码,任何人都可以告诉我为什么只有第一个document.write正在执行而不是其他的.
<!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=iso-8859-1" />
<title>my first java script</title>
</head>
<body>
<script type="text/javascript">
var myhello="hello world, welcome to java script";
var heading="a page of java script";
var linktag="<a href=\"http://www.google.com\">wanna search on google</a>";
var redtext="<span style=\"color:red\">I am so colorful today!</span>";
var begineffect="<strong>";
var endeffect="</strong>";
var beginpara="<p>";
var endpara="</p>";
document.write(begineffect+heading+endeffect);
document.write(begingpara);
document.write(hello);
document.write(endpara);
document.write(begingpara);
document.write(linktag);
document.write(endpara);
document.write(beginpara);
document.write(redtext);
document.write(endpara);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我在所有Web浏览器中测试了以下代码.
它正在生成错误,因为您没有调用的变量 hello
var hello = 'define something here';
document.write(hello);
Run Code Online (Sandbox Code Playgroud)
如果您使用Web检查器,使用像chrome或firefox + firebug这样的好浏览器会显示这样的错误.
http://www.google.com/chrome/intl/en/webmasters-faq.html#jsexec
| 归档时间: |
|
| 查看次数: |
1065 次 |
| 最近记录: |