如何在zIndex中添加“重要" [英] How to add 'important' to zIndex
问题描述
我的网站上的某些加载项之间存在冲突.使用Firebug,我注意到,如果在z-index中添加!important",就可以避免冲突.
I have conflict between some add-ons on my site. Using Firebug, I noticed that if I add "!important" to the z-index I can avoid the conflict.
但是z-index值是使用JavaScript而不是CSS设置的
but the z-index value is set using JavaScript and not CSS
那么我如何在以下JS代码中添加!important":
so how do I add "!important" to the following JS code:
this.menu = $("<ul>")
.addClass("ui-autocomplete")
.appendTo(this.document.find(this.options.appendTo || "body")[0])
.zIndex(this.element.zIndex() + 1) // !! <- here // !!
.hide()
.data("menu");
来自建议的答案[如何使用.css()应用!important?]我了解我需要添加以下代码-
from the proposed answer [How to apply !important using .css()? ] I understand that I need to add the following code -
if (XXX.style.setProperty) { // IE 9- does not support...
XXX.style.setProperty ("z-index", (this???.element.zIndex() + 1), "important");
}
如何添加它:我的情况下,XXX是什么?和这个"?
How do I add it: what is XXX in my case? and "this" ?
Edit 2: Since it became jQuery syntax question, I asked it with different tags in - How to add 'if' to jQuery chain code
推荐答案
I received the answer in another thread - How to add 'if' to jQuery chain code
使用-
.each(function() {
this.style.cssText+= 'z-index: '+(parseInt($(this).css('z-index'))+1)+' !important';
})
但是在几个函数中苦苦挣扎之后,我更愿意在该类中添加一个类和一个规则-
but after struggling with the code in several functions, I preferred to add a class and a rule to this class -
this.menu = $("<ul>")
.addClass("ui-autocomplete")
.addClass("ui-autocomplete-hover-header") // !! added!
. . .
.ui-autocomplete.ui-autocomplete-hover-header {
z-index: 5004 !important; }
这篇关于如何在zIndex中添加“重要"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!