For example<p style="color:red">Set the attribute of p tag<p>
Why use p.style.color?
Why not style.color?
style can be regarded as an object, and color is an attribute. Just use style.color directly.
PHP中文网2017-06-26 10:58:59
No, Style is an attribute of the HTML element, and its value will be parsed by the browser into an inline style.
phpcn_u15822017-06-26 10:58:59
Style itself is an attribute owned by the dom element p, which needs to be accessed through the current element.
Access style.color directly. If the style of which element you want to access cannot be parsed, an error will be reported
女神的闺蜜爱上我2017-06-26 10:58:59
<p style='color:#fff;font-size:16px'>
style belongs to the inline style of p items and elements. It sets the attributes of p. The color and font-size in the attributes are equivalent to the attribute values.
怪我咯2017-06-26 10:58:59
var p = {
style: {
color: '#fff'
}
}
console.log(p.style.color) // #fff
style.color = 'red' // style is not defined
三叔2017-06-26 10:58:59
Style is an attribute and must be behind the object. Just think about it, if you directly style.color, does that change the color of everything? Obviously this is not true.
我想大声告诉你2017-06-26 10:58:59
If you want to set a color style, you should specify whose color to set, right?