A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 一生一世 中级黑马   /  2012-6-22 21:22  /  2093 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

function divAttributes(){//获取属性节点
  var str = "";
  var obj = document.getElementById("divid");
  var att = obj.attributes;
  
  for(var i=0; i<att.length; i++){
   str += "name:"+att[i].nodeName+"  --type:"+att[i].nodeType+"  --value:"+att[i].nodeValue+"<br/>";
  }
  document.write(str);
}

<input type="button" value="小按钮" />
<div id="divid">
nihao
</div>

为什么这个例子的div只有一个属性节点呢??

4 个回复

倒序浏览
请高手指教
回复 使用道具 举报
本帖最后由 丁二跃 于 2012-6-22 21:31 编辑

他不就只有个 id 属性吗……
回复 使用道具 举报
丁二跃 发表于 2012-6-22 21:27
他不就只有个 id 属性吗……


我错了………但是显示的不是一个,是一堆
  1. name:onresizeend --type:2 --value:null
  2. name:onrowenter --type:2 --value:null
  3. name:aria-haspopup --type:2 --value:
  4. name:ondragleave --type:2 --value:null
  5. name:oncut --type:2 --value:null
  6. name:onbeforepaste --type:2 --value:null
  7. name:ondragover --type:2 --value:null
  8. name:onbeforecopy --type:2 --value:null
  9. name:aria-disabled --type:2 --value:
  10. name:onpage --type:2 --value:null
  11. name:onbeforeactivate --type:2 --value:null
  12. name:accessKey --type:2 --value:
  13. name:onfocusin --type:2 --value:null
  14. name:onbeforeeditfocus --type:2 --value:null
  15. name:oncontrolselect --type:2 --value:null
  16. name:aria-hidden --type:2 --value:
  17. name:onloadedmetadata --type:2 --value:null
  18. name:onblur --type:2 --value:null
  19. name:hideFocus --type:2 --value:false
  20. name:style --type:2 --value:null
  21. name:oninput --type:2 --value:null
  22. name:onbeforedeactivate --type:2 --value:null
  23. name:dir --type:2 --value:
  24. name:aria-expanded --type:2 --value:
  25. name:onkeydown --type:2 --value:null
  26. name:ondragstart --type:2 --value:null
  27. name:onscroll --type:2 --value:null
  28. name:onpropertychange --type:2 --value:null
  29. name:ondragenter --type:2 --value:null
  30. name:id --type:2 --value:divid
  31. name:aria-level --type:2 --value:0
  32. name:onrowsinserted --type:2 --value:null
  33. name:onmovestart --type:2 --value:null
  34. name:onabort --type:2 --value:null
  35. name:oncanplay --type:2 --value:null
  36. name:lang --type:2 --value:
  37. name:onmouseup --type:2 --value:null
  38. name:aria-busy --type:2 --value:
  39. name:oncontextmenu --type:2 --value:null
  40. name:onsuspend --type:2 --value:null
  41. name:onpause --type:2 --value:null
  42. name:language --type:2 --value:
  43. name:onratechange --type:2 --value:null
  44. name:onstalled --type:2 --value:null
  45. name:dataSrc --type:2 --value:
  46. name:implementation --type:2 --value:null
  47. name:onerror --type:2 --value:null
  48. name:onbeforeupdate --type:2 --value:null
  49. name:onreadystatechange --type:2 --value:null
  50. name:onload --type:2 --value:null
  51. name:onresize --type:2 --value:null
  52. name:aria-checked --type:2 --value:
  53. name:aria-readonly --type:2 --value:
  54. name:oncopy --type:2 --value:null
  55. name:onchange --type:2 --value:null
  56. name:onselectstart --type:2 --value:null
  57. name:onmove --type:2 --value:null
  58. name:ondragend --type:2 --value:null
  59. name:onrowexit --type:2 --value:null
  60. name:aria-secret --type:2 --value:
  61. name:onactivate --type:2 --value:null
  62. name:onloadeddata --type:2 --value:null
  63. name:onseeking --type:2 --value:null
  64. name:class --type:2 --value:
  65. name:onfocus --type:2 --value:null
  66. name:onmouseover --type:2 --value:null
  67. name:onseeked --type:2 --value:null
  68. name:oncanplaythrough --type:2 --value:null
  69. name:onsubmit --type:2 --value:null
  70. name:onmousemove --type:2 --value:null
  71. name:title --type:2 --value:
  72. name:role --type:2 --value:
  73. name:dataFld --type:2 --value:
  74. name:onfocusout --type:2 --value:null
  75. name:onfilterchange --type:2 --value:null
  76. name:disabled --type:2 --value:false
  77. name:onreset --type:2 --value:null
  78. name:aria-posinset --type:2 --value:0
  79. name:ondrop --type:2 --value:null
  80. name:ondblclick --type:2 --value:null
  81. name:onrowsdelete --type:2 --value:null
  82. name:onplay --type:2 --value:null
  83. name:tabIndex --type:2 --value:0
  84. name:onkeypress --type:2 --value:null
  85. name:aria-relevant --type:2 --value:
  86. name:onlosecapture --type:2 --value:null
  87. name:aria-live --type:2 --value:
  88. name:ondeactivate --type:2 --value:null
  89. name:aria-labelledby --type:2 --value:
  90. name:aria-pressed --type:2 --value:
  91. name:ondatasetchanged --type:2 --value:null
  92. name:ondataavailable --type:2 --value:null
  93. name:aria-invalid --type:2 --value:
  94. name:onafterupdate --type:2 --value:null
  95. name:onmousewheel --type:2 --value:null
  96. name:onkeyup --type:2 --value:null
  97. name:aria-valuenow --type:2 --value:
  98. name:aria-selected --type:2 --value:
  99. name:onmouseout --type:2 --value:null
  100. name:aria-owns --type:2 --value:
  101. name:onvolumechange --type:2 --value:null
  102. name:aria-valuemax --type:2 --value:
  103. name:onplaying --type:2 --value:null
  104. name:onmoveend --type:2 --value:null
  105. name:dataFormatAs --type:2 --value:
  106. name:ontimeupdate --type:2 --value:null
  107. name:oncellchange --type:2 --value:null
  108. name:onloadstart --type:2 --value:null
  109. name:aria-valuemin --type:2 --value:
  110. name:onlayoutcomplete --type:2 --value:null
  111. name:onhelp --type:2 --value:null
  112. name:onerrorupdate --type:2 --value:null
  113. name:contentEditable --type:2 --value:inherit
  114. name:ondurationchange --type:2 --value:null
  115. name:onmousedown --type:2 --value:null
  116. name:onwaiting --type:2 --value:null
  117. name:aria-setsize --type:2 --value:0
  118. name:onpaste --type:2 --value:null
  119. name:onmouseleave --type:2 --value:null
  120. name:onselect --type:2 --value:null
  121. name:onclick --type:2 --value:null
  122. name:ondrag --type:2 --value:null
  123. name:aria-controls --type:2 --value:
  124. name:onresizestart --type:2 --value:null
  125. name:aria-flowto --type:2 --value:
  126. name:ondatasetcomplete --type:2 --value:null
  127. name:aria-required --type:2 --value:
  128. name:onended --type:2 --value:null
  129. name:onemptied --type:2 --value:null
  130. name:aria-describedby --type:2 --value:
  131. name:onmouseenter --type:2 --value:null
  132. name:onbeforecut --type:2 --value:null
  133. name:aria-activedescendant --type:2 --value:
  134. name:aria-multiselectable --type:2 --value:
  135. name:onprogress --type:2 --value:null
  136. name:align --type:2 --value:
  137. name:nofocusrect --type:2 --value:null
  138. name:noWrap --type:2 --value:false
复制代码
回复 使用道具 举报
可是我的输出结果只有一个id属性,并没有这么多的属性呀??这是为什么呢??
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马