六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 32|回复: 0

JS Runcode运行网页上的HTML/CSS/Javascrip代码

[复制链接]

升级  76%

52

主题

52

主题

52

主题

秀才

Rank: 2

积分
164
 楼主| 发表于 2012-12-22 21:14:07 | 显示全部楼层 |阅读模式
<div id="cnblogs_post_body"><div class="cnblogs_Highlighter">


<!DOCTYPE html><html><head><meta charset="gb2312" /><title>runcode-运行HTML/CSS/Jvascrip代码</title></head><body><form>    <textarea name="codearea" style="width:800px; height:600px">        </textarea>        <br />    <input name="run" type="button" value="运行代码"></form><script>(function(){  function run(code){var newWin = window.open("", "_blank", "");newWin.opener = null; // 防止代码对页面修改newWin.document.open();newWin.document.write(code);newWin.document.close();}//遍历页面中运行代码按钮var  executes = document.getElementsByName("run");for(var i=0; i<executes.length; i++){executes[i].onclick = function(){var code = this.form.codearea.value;run(code);};}}());</script></body></html>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表