简体   繁体   English

jQuery:将CSS属性设置为空字符串而不是将其设置为空的效果?

[英]jQuery: effect of setting CSS property to empty string as opposed to setting it to none?

I've seen the following code: 我看过以下代码:

$(this).css('border-color', '');

and wonder whether it is the same as: 想知道它是否与:

$(this).css('border-color', 'none');

or whether in the first case the border-color CSS property is simply reset to its default value from the CSS stylesheet (and if not, then is there a way to reset the value to whatever is default in the stylesheet?). 还是在第一种情况下,只将CSS样式表中的border-color CSS属性重置为默认值(否则,是否可以将其重置为样式表中的默认值?)。 My concern is that I shouldn't have to change the jQuery JavaScript when I change the border-color in the stylesheet. 我担心的是,在样式表中更改border-color时,不必更改jQuery JavaScript。 Things should happen automatically. 事情应该自动发生。

Setting the css value to none is literally setting it to none in css. 将css值设置为none实际上是在css中将其设置为none Setting it to an empty string removes the property from the style attribute on the tag. 将其设置为空字符串会从标记的style属性中删除该属性。

<div style="border-color: none;"></div>

vs

<div style></div>

The reason you'd use none is if you want to overwrite an existing style that sets border-color to something. 不使用none内容的原因是,如果您想覆盖将边框颜色设置为某种东西的现有样式。 If you remove the style from the style attribute then it will fall back to an already defined style for border-color if it exists. 如果从样式属性中删除样式,则样式会退回到边框颜色的已定义样式(如果存在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM