zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js网页中的(运行代码)功能实现思路

JS网页思路代码 实现 功能 运行
2023-06-13 09:14:45 时间
复制代码代码如下:

<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf8"/>
<title>网页中的运行代码功能</title>
<scripttype="text/javascript">
functionrunCode(oCode){
varwin=window.open("","_blank","");
win.document.open("text/html","replace");
win.opener=null
win.document.write(oCode.value);
win.document.close();
}
</script>
</head>
<body>
<textareaid="code1"rows="10"cols="95">
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf8"/>
<title>测试文档</title>
</head>
<body>
测试文档-你可以先修改部分代码再运行
<script>alert("hello")</script>
</body>
</html>
</textarea>
<br>
<inputtype="button"value="运行代码"onclick="runCode(code1)">
</body>
</html>