div.innerHTML="<table>";
div.innerHTML+="<tr><td></td></tr>";
div.innerHTML+="</table>";

解决方案 »

  1.   

    就用innerText,最后需要生成HTML的小时候用"<",">"把"&lt;"," &gt;"替换掉
      

  2.   

    我用div.innerText("<"),的时候他应该自动转为“&lt;"了吧?我如何不让他转呢?
      

  3.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body>
    <script language="JavaScript" type="text/JavaScript">
    var str1
    var str2
    function showIt(){
    str1=document.all.div1.innerHTML
    str2=str1.replace(/&lt;/g,"<").replace(/&gt;/g,">")
    document.body.innerHTML +=str2
    }
    function view(){
    str1=document.all.div1.innerHTML
    str2=str1.replace(/&lt;/g,"<").replace(/&gt;/g,">")
    alert(str1+"已转换为"+str2)
    }
    </script>
    <div id="div1"></div>
    <input type="button" onClick="document.all.div1.innerText += '<table border=1 width=700 height=24>';" value="&lt;table&gt;">
    <input type="button" onClick="document.all.div1.innerText += '<tr>';" value="&lt;tr&gt;">
    <input type="button" onClick="document.all.div1.innerText += '<td>';" value="&lt;td&gt;">
    <input type="button" onClick="document.all.div1.innerText += '</td>';" value="&lt;/td&gt;">
    <input type="button" onClick="document.all.div1.innerText += '</tr>';" value="&lt;/tr&gt;">
    <input type="button" onClick="document.all.div1.innerText += '</table>';" value="&lt;/table&gt;">
    <input type="button" value="查看" onClick="view()">
    <input type="button" value="显示" onClick="showIt()">
    </body>
    </html>