📜  HTML | DOM getAttribute() 方法

📅  最后修改于: 2021-11-07 09:02:45             🧑  作者: Mango

DOM getAttribute()方法用于获取元素的属性值。通过指定属性的名称,它可以获得该元素的值。要从非标准属性中获取值,我们可以使用 getAttribute() 方法。

语法:它返回包含属性值的字符串。

Object.getAttribute(attributename)

示例 1:



  

    DOM getAttribute() Method 

  

    
        

              GeeksForGeeks          

           

DOM getAttribute() Method

        
                 

                   
  

输出:
在点击按钮之前:

点击按钮后:

示例 2:



  

    DOM getAttribute() Method 

  

    
        

                  GeeksForGeeks              

        

DOM getAttribute() Method

                   Geeksforgeeks                  
        
                 
        

                   
  

输出:
在点击按钮之前:

点击按钮后:

支持的浏览器: DOM getAttribute() 方法支持的浏览器如下:

  • 谷歌浏览器 15.0
  • 浏览器 11.0
  • 火狐 15.0
  • 歌剧 15.0
  • Safari 6.0