经常在一些js特效的网站上看到这样的功能:可以点击一个按纽,运行文本框中的代码。
具体代码如下:
[code]
<HTML><BODY>
<textarea name="t11" id="t11" rows="12" cols="95">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
body{font-size:12px;}
</style>
</HEAD>
<BODY>
<span onclick="aaa()" style="text-decoration:underline;cursor:hand">asp编程网</span>
<script language="javascript">
function aaa()
{
window.open('http://www.aspprogram.cn');
}
</script>
</BODY>
</HTML>
</textarea>
<br>
<input type="button" value="运行代码" style="border-left:1px solid #B1B4CD;border-right:1px solid #494D74;border-top:1px solid #B1B4CD;;border-bottom:1px solid #494D74;background:#696D81;color:#FFFFFF;" onclick="runCode(document.getElementById('t11'))">
<script language="javascript">
function runCode(obj)
{
var winname = window.open('', "_blank", '');
winname.document.open('text/html', 'replace');
winname.opener = null // 防止代码对论谈页面修改
winname.document.write(obj.value);
winname.document.close();
}
</script></body></html>
[/code]