在textarea文本域中显示HTML代码的方法

  这是一个iframe 的

  给你一个参考的:

  

复制代码 代码如下:

  <iframe ID="tryit" MARGINHEIGHT="1" MARGINWIDTH="1" width="100%" height="300" scrolling="auto"></iframe>

  <script language=javascript>

  tryit.document.designMode="On";

  tryit.document.open();

  tryit.document.innerHTML+=tryit.document.write("<b>asdf</b>");

  tryit.document.close();

  tryit.focus();

  </script>

  这个是textarea

  

复制代码 代码如下:

  <body>

  <textarea id="txt" rows=10 cols=10></textarea>

  <button onclick="insert()">click</button>

  <script>

  function insert(){

  var oDiv=document.createElement("DIV");

  oDiv.innerHTML="<br><Font color = Red>red<BR></FONT><Font color = Blue>blue</font>";

  document.getElementById("txt").appendChild(oDiv);

  }

  </script>