[英]Can jQuery css get inline styles also?
As far as I know $(element).css()
can get linked stylesheet information specific to the element.据我所知
$(element).css()
可以获得特定于元素的链接样式表信息。 Can .css()
also get inline styles? .css()
也可以获得内联样式吗? If so, do I need to specify different parameter value?如果是这样,我是否需要指定不同的参数值? For example, if I need to get background color, should I call both
$(element).css('background-color')
and $(element).css('backgroundColor')
?例如,如果我需要获取背景颜色,是否应该同时调用
$(element).css('background-color')
和$(element).css('backgroundColor')
?
As people have said in the comments, this question is something that you might have easily found out for yourself.正如人们在评论中所说的那样,您可能很容易自己发现这个问题。 Since we're here anyway though, here's the answer:
不过既然我们都来了,下面是答案:
The .css() function can read both inline styles and separate styles (via link or style tags), but when it does write styles (when it has a parameter), it only modifies the inline style of the element. .css() 函数可以读取内联样式和单独的样式(通过链接或样式标签),但是当它确实写入样式时(当它有参数时),它只会修改元素的内联样式。
var colorspan = document.createElement("span");
colorspan.setAttribute('style','width:25px; height:25px');
colorspan.setAttribute('id','promotcolor');
var pormot = document.getElementById("promotcolor");
pormot.style.backgroundColor = color;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.