实现蓝色理想的"运行代码"

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

效果如下,代码在下面:



 

代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<script>
function runCode() //定义一个运行代码的函数,
{
var code=RunCode.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() value=运行代码>
</body>
</html>

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