動態載入js和css的jquery plugin (Jquery外掛程式)

來源:互聯網
上載者:User
放在javascript檔案頭部,就像C#(using...)或Java(import ...)

 

$.extend({
 includePath: '',
 include: function(file) {
 var files = typeof file == "string" ? :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 + ">");
 }
 }
});

 

調用方式

$.includePath = 'JS或者CSS的路徑';

$.include(['jquery.tree.js', 'jquery.tree.css']); 

 原文地址:http://www.cnblogs.com/chenjinfa/archive/2009/03/17/1414178.html 

 

下載

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.