简体   繁体   中英

Including JavaScript and CSS in a page (jQuery)

I recently came across the includeMany jQuery plugin to include external JavaScript and CSS files into a page. Although it was released in early 2009 there are NO references in blogs or elsewhere. I wonder if it's usable? What is the experience using it?

You can include JavaScript and CSS using the example below. There is no need for any plugins.

To include JavaScript code, do this:

$.getScript("youpathtoscript.js",function() {
            //this script is loaded
});

To include CSS files:

$("<link/>", {
   rel: "stylesheet",
   type: "text/css",
   href: "styles/yourcss.css"
}).appendTo("head");

For collection of CSS/JavaScript import (including):

Eval alternative:

$("<script></script>", {type: "text/javascript",})
.text("alert('your function');")
.appendTo("head");

Embedded CSS:

$("<style></style>", {type: "text/css",})
.text("#you{css:rule}")
.appendTo("head");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM