日期:2014-05-16 浏览次数:20421 次
<html>
<head>
<title> Untitled Document </title>
<script type ="text/javascript">
// 同样的两次调用document.write(),为什么一会发生错误,一个不会?
function learn_write_wrong(){
var pre = document.getElementsByTagName("pre");
document.write(pre[0].innerHTML, "<br />");
document.write(pre[0].id, "<br />"); // 这句话发生了错误! why?
}
function learn_write_right(){
document.write("right", "<br />");
document.write("right yeah!", "<br />");
}
</script>
</head>
<body>
<pre id = "实验document.write()方法">
网页原内容
</pre>
<input type = "button" value = "错误" onclick = "javascript: learn_write_wrong();" />
<input type = "button" value = "正确" onclick = "javascript: learn_write_right();" />
</body>
</html>