当前位置: 移动技术网 > IT编程>开发语言>其他编程 > cnblogs 运行代码功能尝试

cnblogs 运行代码功能尝试

2017年12月08日  | 移动技术网IT编程  | 我要评论
首先定义个文本域并且给个id
<textarea id="o_txt_1" rows="8" cols="80"> <!--要运行的代码--> </textarea>
然后定义个按钮
<input type="button" value="运行代码" onclick="runcode('o_txt_1')" />
最后当然是要写函数了,代码如下:
复制代码 代码如下:

function runcode(id){
var obj=document.getelementbyid(id);
var win = window.open('', "_blank", '');
win.document.open('text/html', 'replace');
win.opener = null;
win.document.write(obj.value);
win.document.close();
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网