我希望在一个Ajax调用内指定外部样式表,您需要使用jQuery实现此目标(如下所示),但我需要将该方法适配到dojo JavaScript框架。
JQuery示例
$('head').append('<link rel="stylesheet" type="text/css" href="lightbox_stylesheet.css">');
谢谢。
我希望在一个Ajax调用内指定外部样式表,您需要使用jQuery实现此目标(如下所示),但我需要将该方法适配到dojo JavaScript框架。
$('head').append('<link rel="stylesheet" type="text/css" href="lightbox_stylesheet.css">');
一旦您包含了dojo.NodeList-manipulate
,它与jQuery几乎完全相同:
dojo.require("dojo.NodeList-manipulate");
dojo.ready(function(){
dojo.query("head").append('<link rel="stylesheet" type="text/css" href="lightbox_stylesheet.css">');
});
尝试使用dojo.query
dojo.query("head").forEach(function(node, index, array){
// append content af final of head
node.innerHTML += '<link rel="stylesheet" type="text/css" href="lightbox_stylesheet.css">';});
我想出了
经过一些尝试,我想出了以下方法:
function require_css(href)
{
if (typeof href == 'undefined' || href.length == 0) return false;
var link = dojo.create("link",
{
type : "text/css",
rel : "stylesheet",
href : href
});
dojo.doc.getElementsByTagName("head")[0].appendChild(link);
console.log("loading : css : "+ href);
}
谢谢大家的意见,我更喜欢 thirtydot 的方法 :D..
dojo.require("dojo.NodeList-manipulate");
这行代码需要放在你的代码/文件的顶部,就像紧接着<script>
之后(或者类似这样,我不是特别熟悉 Dojo)。这里是它的工作示例:http://jsfiddle.net/thirtydot/e9q2u/ - thirtydot