"运行代码"按钮的实现 [第二版]

类别:网站制作 点击:0 评论:0 推荐:

根据小雨朋友的意见修改了一下,给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>


本文地址:http://com.8s8s.com/it/it31131.htm