<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>write用法</title>
<script language="javascript">
var num=0;
document.write=function(str){
document.body.innerHTML=str+document.body.innerHTML;
}
function show()
{
document.write("<center><table width=400 height=200 style=\"border:2px solid #9badce;\">");
document.write("<tr>");
document.write("<td>hello</td><td>123</td>");
document.write("</tr></table></center>");
}
</script>
</head>
<body>
<input type="button" value="显示内容" onClick="show();">
</body>
</html>如果在show函数中只写一个document,那么是可以不覆盖输出的,但是问题是,现在我写了很多document,构成一个表格,但是输出却不是一个正常的表格,,太难了吧

解决方案 »

  1.   

    你在这样试试看function show()
    {
    var t = "<center><table width=400 height=200 style=\"border:2px solid #9badce;\">";
    t += "<tr>";
    t += "<td>hello</td><td>123</td>";
    t += "</tr></table></center>"
    document.write(t);
    }
      

  2.   

    document.write=function(str){
    document.body.innerHTML=str+document.body.innerHTML;
    }
    这个起了奇怪的作用。看起来不是表格,这句去了一切不就都正常了!
    那些罗嗦复杂的专业语言我也不知道该怎么说,反正这么做就对了!
      

  3.   

    document.write=function(str){
    document.body.innerHTML=str+document.body.innerHTML;
    }
    这个是防止覆盖的,,如果没有这句话,会清空原先内容的,明白不???
      

  4.   

    顺序反了吧?这样顺序添加1、2,结果就成了 2+1+原内容 了。document.body.innerHTML += str;