cnsevennight

html代码

<textarea name="textarea" cols="60" rows="10" id="rn01">运行的代码</textarea> <br>
<input onclick="runWin(\'rn01\')" type="button" value="运行代码" style="cursor:hand"> 点击“运行代码”

JS代码

 

<script language="JavaScript" type="text/JavaScript">
//运行文本域代码
function runWin(code) {
    cod=document.all(code)
    var code=cod.value;
    if (code!=""){
    var newwin=window.open(\'\',\'\',\'\'); //打开一个窗口并赋给变量newwin。
    newwin.opener = null // 防止代码对页面修改
    newwin.document.write(code); //向这个打开的窗口中写入代码code,这样就实现了运行代码功能。
    newwin.document.close();
    }
}
</script>

 

 效果展示:


点击“运行代码”

分类:

技术点:

相关文章:

  • 2021-11-13
  • 2022-01-02
  • 2021-11-03
  • 2019-01-21
  • 2021-11-19
  • 2021-12-07
  • 2021-12-27
猜你喜欢
  • 2022-01-07
  • 2021-08-14
  • 2021-11-30
  • 2021-09-15
  • 2021-12-16
  • 2021-11-30
  • 2021-10-12
相关资源
相似解决方案