jquery getScript动态加载JS

使用场景:网站layout 需要引入大量js文件,某个功能需要时再将相应的js动态加载进来。

getScript() 方法通过 HTTP GET 请求载入并执行 JavaScript 文件。

 jQuery(function ()
        {

            alert(1);
        // 未加载js时,报错
             var ss = "111";
                hex_md5(ss);
                alert(hex_md5(ss));
            jQuery.getScript('http://www.cnblogs.com/../Content/javascript/md5.js').done(function ()
            {
                alert(2);
    // 加载js,正常使用
                var ss = "111";
                hex_md5(ss);
                alert(hex_md5(ss));
                
                // 延迟加载
                //setTimeout("funQuery(300)", 5000);
              
            });
        })    
View Code

参考资料:http://www.cnblogs.com/cuitsl/archive/2012/11/15/2771549.html

posted @ 2013-05-17 10:50  365lei  阅读(260)  评论(0编辑  收藏  举报