网络编程 
首页 > 网络编程 > 浏览文章

cnblogs 运行代码功能尝试

(编辑:jimmy 日期: 2024/9/23 浏览:3 次 )
首先定义个文本域并且给个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();
}
上一篇:windows 中 \r\n 区别于 类unix中的\n 疑问理解(crlf回车换行)
下一篇:变量、函数、类的命名规则