jQuery中的Asset.css [英] Asset.css in jQuery

查看:115
本文介绍了jQuery中的Asset.css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用Mootools类Asset在运行时包含CSS和JS文件.下面的行用于包含CSS文件:

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');

我需要将此行更改为jQuery,因为脚本的其余部分已经在jQuery中.我们如何在jQuery中做到这一点?

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?

推荐答案

有一种简单的方法可以用普通的javascript实现.只需尝试以下几行,瞧!

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) ;
}

这篇关于jQuery中的Asset.css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆