问题
My application uses a Mootools class Asset to include CSS and JS files at run time. The line below used to include a CSS file:
var myStyleSheet = Asset.css('/styles/myStyle.css');
I need to change this line to jQuery since the rest of the script is already in jQuery. How can we do that in jQuery?
回答1:
There is a simple way to do it in plain javascript.. Just try the below lines and voila !!
var cssfile=document.createElement("link") ;
cssfile.setAttribute("rel", "stylesheet");
cssfile.setAttribute("type", "text/css");
cssfile.setAttribute("href", "/styles/myStyle.css");
if (typeof cssfile!="undefined") {
document.getElementsByTagName("head")[0].appendChild(cssfile) ;
}
来源:https://stackoverflow.com/questions/14473120/asset-css-in-jquery