javascript - Set inline style attributes.
黄舟
黄舟 2017-06-26 10:56:59
0
6
721

For example

Set the attribute of p tag


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.

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all (6)
洪涛

No, Style is an attribute of the HTML element, and its value will be parsed by the browser into an inline style.

    phpcn_u1582

    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

      女神的闺蜜爱上我

      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.

        刘奇
        var p = { style: { color: '#fff' } } console.log(p.style.color) // #fff style.color = 'red' // style is not defined
          三叔

          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.

            我想大声告诉你

            If you want to set a color style, you should specify whose color to set, right?

              Latest Downloads
              More>
              Web Effects
              Website Source Code
              Website Materials
              Front End Template
              About us Disclaimer Sitemap
              php.cn:Public welfare online PHP training,Help PHP learners grow quickly!