jQuery 设置显示:块!重要
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7389397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:47:18 来源:igfitidea点击:
Setting display: block !Important
提问by Toni Michel Caubet
There is a problem with a rollover doesn't want to show its content and if I do
有一个翻转的问题,不想显示其内容,如果我这样做
#callCenter {
position: fixed;
z-index: 2411 !important;
display: block !important; /* please note here !important */
right: 110px;
}
It's shown, but if I do: (so the div is hidden until another element is clicked)
它已显示,但如果我这样做:(因此 div 被隐藏,直到单击另一个元素)
#callCenter {
position: fixed;
z-index: 2411 !important;
right: 110px;
}
And
和
$('#telefonosCabecera').click(function(){
$("#callCenter").css('display','block!important'); // or 'block !important'
alert('done')
});
I don't see #callCenter
but I do see the alert.
我没有看到,#callCenter
但我确实看到了警报。
What could be the reason for this?
这可能是什么原因?
回答by Phoenix
You need to do one of the following:
您需要执行以下操作之一:
- Add a class with the !important rule (i.e.:
.myClass{display:block !important;}
) and then add the class to the element - Add the css attribute via
$('#myElement').attr('style','display: block !important');
- 使用 !important 规则添加一个类(即:)
.myClass{display:block !important;}
,然后将该类添加到元素 - 通过添加css属性
$('#myElement').attr('style','display: block !important');