全局作用域的求值 globalEval

function globalEval(data){
    data = data.replace(/^\s* | \s*$/g,"");
    if(data){
        var head = document.getElementsByTagName("head")[0] || document.documentElement,script = document.createElement("script");
        
        script.type = "text/javascript";
        script.text = data;
        
        head.appendChild(script);
        head.removeChild(script);
        
    }
}

 

posted @ 2017-11-21 22:42  halo-漾  阅读(147)  评论(0编辑  收藏  举报