Home  >  Q&A  >  body text

为什么这里不能通过getAttribute()方法获取nodeName属性值?

为什么这里不能通过getAttribute()方法获取nodeName属性值?


尼古拉阿列克塞耶维奇奥斯特洛夫斯基尼古拉阿列克塞耶维奇奥斯特洛夫斯基2832 days ago751

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:20:59

    Why can’t the nodeName attribute value be obtained through the getAttribute() method here? -PHP Chinese website Q&A-Why can't the nodeName attribute value be obtained through the getAttribute() method here? -PHP Chinese website Q&A

    Please watch and learn.

    reply
    0
  • 巴扎黑

    巴扎黑2016-12-21 11:18:38

    getAttribute()方法只能获取元素中已存在属性的属性值,而nodeName是每一个节点自带的静态属性而不是我们自己定义的属性,所以不能使用getAttribute()方法获取nodeName属性值

    例如:<p class="message" id="text" width="200px" height="50px">这是一个p标签</p>

    我们可以使用getAttribute()方法获取class、id、width、height等属性的属性值,但不可以使用getAttribute()方法获取nodeName属性值,因为我们没用写一个className属性


    reply
    0
  • Cancelreply