ajax請求html頁面js不執行


evalScripts(text){
        let script
        , regexp = /<script(?:\s+src=('|")([\w.-/]+?)\1)?\s*>\s*([\s\S]*?)\s*<\/script>/gi
        , head = document.querySelectorAll('head')[0]
        , createScript = function(src,callback){
            let node = document.createElement('script');
            node.type = 'text/javascript';
            node.onload = node.onreadystatechange = function() {
                if(!/*@cc_on!@*/0 || this.readyState === 'loaded' || this.readyState === 'complete') {
                    this.onload = this.onreadystatechange = null; 
                    this.parentNode.removeChild(this);
                    typeof callback == 'function' && callback()
                }
            }
            node.src = src;
            return node;
        }
        ,serializeScript = function(){
            script = regexp.exec(text);
            if(!script){return}
            if(script[2]){
                let node = createScript(script[2],function(){
                    serializeScript(text)
                })
                head.appendChild(node)
            }else{
                window.execScript ? execScript(script[3]) : eval(script[3])
                serializeScript(text)
            }
        }
        serializeScript();
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM