根据小雨朋友的意见修改了一下,给runcode加了个参数,不会显的所谓“太死”:(第一版:http://blog.csdn.net/catally/archive/2004/11/13/180487.aspx)
代码:
<html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <title>新建网页 1</title> </head> <body> <script> function runcode(txtarget) //定义一个运行代码的函数, { var code=txtarget.value;//要运行的代码,即textarea的内容,runcode是textarea的name。 var newwin=window.open('','',''); //打开一个窗口并赋给变量newwin。 newwin.opener = null // 防止代码对页面修改 newwin.document.write(code); //向这个打开的窗口中写入代码code,这样就实现了运行代码功能。 newwin.document.close(); } </script> <textarea name="runcode" style="width:274; height:167"> <b>welcome to c's blog:</b><br> <a href="http://blog.csdn.net/catally">http://blog.csdn.net/catally</a> </textarea><br> <input name="button" type=button onclick=runcode(runcode) value=运行代码><br> <textarea name="runcode2" style="width:274; height:167"> <b><i>c!!!!!</i></b><br>i love you </textarea><br> <input name="button" type=button onclick=runcode(runcode2) value=运行代码> </body> </html>
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)