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


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

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();
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3