网页“运行代码”的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">function Preview(obj) { var TestWin=window.open('','',''); TestWin.opener = null; TestWin.document.write(obj.value); TestWin.document.close(); } function copyCode(obj) { var rng = document.body.createTextRange(); rng.moveToElementText(obj); rng.scrollIntoView(); rng.select(); rng.execCommand("Copy"); rng.collapse(false); alert("复制成功!") } function saveCode(obj) { var winname = window.open('', '_blank', 'top=10000'); winname.document.open('text/html', 'replace'); winname.document.writeln(obj.value); winname.document.execCommand('saveas','','SaveCode.htm'); winname.close(); } </script>

</head>
<body>
<textarea id="code1" style="width:630px;height:240px;" name="code1" rows="15" cols="80"></textarea> <input id="yxdm" type="button" value="运行代码" name="yxdm" onclick="Preview(document.getElementById('code1'))" /> <input id="fzdm" type="button" value="复制代码" name="fzdm" onclick="copyCode(document.getElementById('code1'))" /> <input type="button" name="lzdm" id="lzdm" value="另存代码" onclick="saveCode(document.getElementById('code1'))" /> 
</body>
</html>

posted @ 2012-03-26 15:29  憶言  阅读(259)  评论(0编辑  收藏  举报