现在的位置: 首页 > 综合 > 正文

js实现运行代码需要刷新的解决方法

2012年09月20日 ⁄ 综合 ⁄ 共 324字 ⁄ 字号 评论关闭

现在大多网站都有“运行代码”的功能,搜索吧也很早就实现了这个功能,但最近在做一个项目时,发现有些需要刷新才能看到结果,自己摸索了下,其实解决方法很简单,看如下代码:

function runCode(cod1) {
cod=document.getElementById(cod1)
var code=cod.innerText;
var newwin=window.open('','','');
newwin.opener = null;
newwin.document.write(code);
newwin.location.reload();
newwin.document.close();
}
只要加上这句就可以了:

newwin.location.reload();

抱歉!评论已关闭.