论坛和博客常用的HTML代码测试框

经常看到各大源码网站中的HTML代码测试框

如下 ↓↓↓↓↓↓↓↓↓↓↓↓ 


  [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

 

 

实现代码

 1 <html> 
 2 <head> 
 3 <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
 4 <title>runcode</title> 
 5 </head> 
 6  
 7 <body> 
 8 <script language="JavaScript" type="text/JavaScript"> 
 9 //运行文本域代码
10 function runEx(cod1) {
11  cod=document.all(cod1)
12  var code=cod.value;
13  if (code!=""){
14  var newwin=window.open('','',''); //打开一个窗口并赋给变量newwin。
15  newwin.opener = null // 防止代码对论谈页面修改
16  newwin.document.write(code); //向这个打开的窗口中写入代码code,这样就实现了运行代码功能。
17  newwin.document.close();
18 }
19 }
20 </script> 
21 <textarea name="textarea" cols="60" rows="10" id="rn01"><font color="red">加入HTML代码</font></textarea> 
22 <br><INPUT onclick="runEx('rn01')" type="button" value="运行代码" style="cursor:hand">&nbsp;&nbsp;[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
23 </body> 
24 </html>

 

 

posted @ 2010-07-27 09:49  lxnjy  阅读(5748)  评论(0编辑  收藏  举报