我动态加载一个css样式表(从jQuery的一点帮助),如下所示:
var head = document.getElementsByTagName('head')[0];
$(document.createElement('link'))
.attr({ type: 'text/css', href: '../../mz/mz.css', rel: 'stylesheet' })
.appendTo(head);
Run Code Online (Sandbox Code Playgroud)
这适用于Firefox和谷歌浏览器,但不适用于IE.
有帮助吗?谢谢
我在服务器上加载了一个css文件,所以我有一个URL跟我一起.如何使用JQuery在我的perl代码中加载它?
所以目前我在我的梅森页面中硬编码css,页面上缺少这样的东西
JQ.onReady('show', function(){
JQ.addStyles({styles: ["\n\n.ap_classic { border-top:1px solid #ccc;border-left:1px solid #ccc;border-bottom:1px solid #2F2F1D; border-right:1px solid #2F2F1D;background-color:#EFEDD4;padding:3px; } .ap_classic .ap_titlebar { color:#86875D;font-size:12px;padding:0 0 3px 0;line-height:1em; } .ap_classic .ap_close { float:right; } .ap_classic .ap_content { clear:both;background-color:white;border:1px solid #ACA976;padding:8px;font-size:11px; } "]});
});
Run Code Online (Sandbox Code Playgroud)
我想避免硬编码这个CSS?
我们使用jQuery来解析一些HTML.然后我需要遍历该文档并找到一些元素.在我需要找到的<link>元素中,有元素.
这非常适合提取所有<a>元素:
$(string).find("a")
Run Code Online (Sandbox Code Playgroud)
但这不能提取<link>元素:
$(string).find("link")
Run Code Online (Sandbox Code Playgroud)
该string参数是HTML内容(例如,在请求中接收).
知道为什么吗?(我想find这只适用于<body>元素).另外,关于如何实际提取这些<link>元素的任何想法?
我正在尝试使用附加css文件
$('head').append('<link rel="stylesheet" href="style2.css" type="text/css" />');
这很好 - 但是,我有一些功能在css添加后运行,我无法找到让这些文件等到这个文件完成加载的方法?
我怎样才能做到这一点 ?
到目前为止,我能够通过在html文件中包含javascript来创建一个绑定到鼠标右键的contextMenu:
var Feature = {
register_contextMenu: function() {
$.contextMenu({
selector: '*',
items: {
"item_one": { name: "Item_one", icon: "./path1" },
"item_two": { name: "item_two", icon: "./path2" }
}
});
}
};
$(document).ready(Feature.register_contextMenu);
Run Code Online (Sandbox Code Playgroud)
如何在选项旁边显示图标?
插件的文档(http://medialize.github.io/jQuery-contextMenu/)提到必须使用某些选择器在CSS中定义图标.
在这种情况下如何使用CSS和contextMenu?