属性定义

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6     </head>
 7     <body>
 8         window.onload=function(){
 9     var _oDiv=document.getElementById('oDiv');
10     //_oDiv.index=0;
11     //alert(_oDiv.index)
12     //alert(_oDiv.b)
13     
14     //两种方法不能通用
15     
16     //_oDiv.setAttribute('a','a1');//属性名,属性值;设置
17     //alert(_oDiv.getAttribute('a'))//获取
18     //alert(_oDiv.getAttribute('b'))
19     //alert(_oDiv.getAttribute('index'))
20     
21     _oDiv.setAttribute('style','color:red');
22     
23     _oDiv.removeAttribute('style');//删除
24     
25 }
26     </body>
27 </html>
原文地址:https://www.cnblogs.com/thestudy/p/6292181.html