Very concise dynamic loading of JS and CSS jquery plugin

Source: Internet
Author: User

1//plugin author:chenjinfa@gmail.com
2//Plugin Name: $.include
3//$.include (' file/ajaxa.js '); $.include (' file/ajaxa.css ');
4//or $.includepath = ' file/'; $.include ([' Ajaxa.js ', ' ajaxa.css ']);
5
6$.extend ({
7 Includepath: ',
8 Include:function (file) {
9 var files = typeof File = = "string"? [File]:file;
for (var i = 0; i < files.length; i++) {
One 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 +) > ");
19}
20}
21});

On the head of the JavaScript file, just like C # (using ...). or Java (import ...). )

Example: Department Admin page Department.aspx

Note: Because of the editor's question, the content (http://www.cnblogs.com) is the original. . / . . /”

.
<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>

The Include plugin code is placed in the public common.js.

Departmentinfo.js File Code

$.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"
  });
  .
});
.

That's a pretty good way to do it.

Later I will be free to publish the whole project and experience I wrote. A framework system based on ASP.net Data Service and jquery, named "E-frame", realizes the function of role-based privilege system.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.