如何使用jQuery设置多个CSS显示属性值 [英] How to set multiple CSS display property values with jquery
问题描述
好吧,这让我有点生气了.我正在将jQuery .css()方法用于 try 来设置类所需的多个flexbox显示属性.问题是,它只保留最后一个.关于如何使用jQuery的任何想法,还是不可能?
Ok, this is driving me a bit batty. I am using the jQuery .css() method to try to set the multiple flexbox display properties needed for a class. Problem is, it only keeps the last one. Any idea on how to do this with jQuery, or is it not possible?
这是我到目前为止尝试过的:
Here's what I've tried so far:
$(".department-name").css({
'display' : '-webkit-box',
'display' : '-webkit-flex',
'display' : '-moz-box',
'display' : '-ms-flexbox',
'display' : 'flex'
});
那是行不通的,它只会获取最后一个而不是其他.我正在根据页面上具有多少行换行(高度)来处理页面上的文本元素,并想用display:none(初始CSS值)将其隐藏,对其进行处理,然后使用之前具有的flex属性显示它开始更改JS代码以处理多行问题.想法?
That doesn't work, it just gets the last one and not the others. I am manipulating a text element on a page based on how many line wraps it has (its height) and want to hide it with display:none (initial CSS value), manipulate it, then display it with the flex properties it had before I started changing the JS code to deal with the multiple line problem. Ideas?
推荐答案
$('.department-name').addClass('test1');
css:
.test1{
display : -webkit-box;
display : -webkit-flex;
display : -moz-box;
display : -ms-flexbox;
display : flex;
}
您可以使用addClass()
方法将测试类添加到元素中. css()
方法中的display属性必须被覆盖,因此最后一个仅适用.
You can use addClass()
method to add test class into your element. in css()
method display property must be getting overrides hence the last one is only applying.
这篇关于如何使用jQuery设置多个CSS显示属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!