转自:
cnblogs 运行代码功能尝试,使用cnblogs的朋友可以参考下。
1 21 22 23 32 33 34 35 37 38 39
首先定义个文本域并且给个ID
<textarea id="O_txt_1" rows="8" cols="80"> <!--要运行的代码--> </textarea> 然后定义个按钮 <input type="button" value="运行代码" οnclick="runCode('O_txt_1')" /> 最后当然是要写函数了,代码如下:1 function runCode(id){ 2 var obj=document.getElementById(id); 3 var win = window.open('', "_blank", ''); 4 win.document.open('text/html', 'replace'); 5 win.opener = null; 6 win.document.write(obj.value); 7 win.document.close(); 8 }