Asset.css in jQuery

只谈情不闲聊 提交于 2019-12-24 11:47:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!