您的位置:首页 > Web前端 > JavaScript

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

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

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(); 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐