日期:2014-05-16  浏览次数:20563 次

JavaScript和Jquery动态加载Js文件和Css文件
1. jQuery自身方法
$.load()  //方法
$.getScript()  //方法



2. JavaScript和Jquery动态加载Js文件和Css文件 http://www.phpernote.com/jquery/107.html
// plugin author :  chenjinfa@gmail.com
// plugin name : $.include
// $.include('file/ajaxa.js');$.include('file/ajaxa.css');
//  or $.includePath  = 'file/';$.include(['ajaxa.js','ajaxa.css']);

$.extend({
     includePath: '',
     include: function(file) {
        var files = typeof file == "string" ? [file]:file;
        for (var i = 0; i < files.length; i++) {
            var name = files[i].replace(/^\s|\s$/g, "");
            var att = name.split('.');
            var ext = att[att.length - 1].toLowerCase();
            var isCSS = ext == "css";
            var tag = isCSS ? "link" : "script";
            var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
            var link = (isCSS ? "href" : "src") + "='" + $.includePath + name + "'";
            if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
        }
   }
});



<head>
   <link rel="stylesheet" href="http://www.cnblogs.com/css/common.css" type="text/css"/>
   <script src="http://www.cnblogs.com/javascript/jquery.js" type="text/javascript"></script>
   <script src="http://www.cnblogs.com/javascript/common.js" type="text/javascript"></script>
   <script src="DepartmentInfo.js" type="text/javascript"></script>
</head>



$.includePath = 'http://www.cnblogs.com/javascript/';
$.include(['json2.js', 'jquery.tree.js', 'jquery.tree.css']);

$(function() {
  $("#depTree").tree({
    url: "http://www.cnblogs.com/service/ES_SYSTEM.svc/DEP_INFO_Tree"
  });
  .
});