黑马程序员技术交流社区
标题:
js获取属性节点的问题
[打印本页]
作者:
一生一世
时间:
2012-6-22 21:22
标题:
js获取属性节点的问题
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只有一个属性节点呢??
作者:
一生一世
时间:
2012-6-22 21:22
请高手指教
作者:
丁二跃
时间:
2012-6-22 21:27
本帖最后由 丁二跃 于 2012-6-22 21:31 编辑
他不就只有个 id 属性吗……
作者:
丁二跃
时间:
2012-6-22 21:38
丁二跃 发表于 2012-6-22 21:27
他不就只有个 id 属性吗……
我错了………但是显示的不是一个,是一堆
name:onresizeend --type:2 --value:null
name:onrowenter --type:2 --value:null
name:aria-haspopup --type:2 --value:
name:ondragleave --type:2 --value:null
name:oncut --type:2 --value:null
name:onbeforepaste --type:2 --value:null
name:ondragover --type:2 --value:null
name:onbeforecopy --type:2 --value:null
name:aria-disabled --type:2 --value:
name:onpage --type:2 --value:null
name:onbeforeactivate --type:2 --value:null
name:accessKey --type:2 --value:
name:onfocusin --type:2 --value:null
name:onbeforeeditfocus --type:2 --value:null
name:oncontrolselect --type:2 --value:null
name:aria-hidden --type:2 --value:
name:onloadedmetadata --type:2 --value:null
name:onblur --type:2 --value:null
name:hideFocus --type:2 --value:false
name:style --type:2 --value:null
name:oninput --type:2 --value:null
name:onbeforedeactivate --type:2 --value:null
name:dir --type:2 --value:
name:aria-expanded --type:2 --value:
name:onkeydown --type:2 --value:null
name:ondragstart --type:2 --value:null
name:onscroll --type:2 --value:null
name:onpropertychange --type:2 --value:null
name:ondragenter --type:2 --value:null
name:id --type:2 --value:divid
name:aria-level --type:2 --value:0
name:onrowsinserted --type:2 --value:null
name:onmovestart --type:2 --value:null
name:onabort --type:2 --value:null
name:oncanplay --type:2 --value:null
name:lang --type:2 --value:
name:onmouseup --type:2 --value:null
name:aria-busy --type:2 --value:
name:oncontextmenu --type:2 --value:null
name:onsuspend --type:2 --value:null
name:onpause --type:2 --value:null
name:language --type:2 --value:
name:onratechange --type:2 --value:null
name:onstalled --type:2 --value:null
name:dataSrc --type:2 --value:
name:implementation --type:2 --value:null
name:onerror --type:2 --value:null
name:onbeforeupdate --type:2 --value:null
name:onreadystatechange --type:2 --value:null
name:onload --type:2 --value:null
name:onresize --type:2 --value:null
name:aria-checked --type:2 --value:
name:aria-readonly --type:2 --value:
name:oncopy --type:2 --value:null
name:onchange --type:2 --value:null
name:onselectstart --type:2 --value:null
name:onmove --type:2 --value:null
name:ondragend --type:2 --value:null
name:onrowexit --type:2 --value:null
name:aria-secret --type:2 --value:
name:onactivate --type:2 --value:null
name:onloadeddata --type:2 --value:null
name:onseeking --type:2 --value:null
name:class --type:2 --value:
name:onfocus --type:2 --value:null
name:onmouseover --type:2 --value:null
name:onseeked --type:2 --value:null
name:oncanplaythrough --type:2 --value:null
name:onsubmit --type:2 --value:null
name:onmousemove --type:2 --value:null
name:title --type:2 --value:
name:role --type:2 --value:
name:dataFld --type:2 --value:
name:onfocusout --type:2 --value:null
name:onfilterchange --type:2 --value:null
name:disabled --type:2 --value:false
name:onreset --type:2 --value:null
name:aria-posinset --type:2 --value:0
name:ondrop --type:2 --value:null
name:ondblclick --type:2 --value:null
name:onrowsdelete --type:2 --value:null
name:onplay --type:2 --value:null
name:tabIndex --type:2 --value:0
name:onkeypress --type:2 --value:null
name:aria-relevant --type:2 --value:
name:onlosecapture --type:2 --value:null
name:aria-live --type:2 --value:
name:ondeactivate --type:2 --value:null
name:aria-labelledby --type:2 --value:
name:aria-pressed --type:2 --value:
name:ondatasetchanged --type:2 --value:null
name:ondataavailable --type:2 --value:null
name:aria-invalid --type:2 --value:
name:onafterupdate --type:2 --value:null
name:onmousewheel --type:2 --value:null
name:onkeyup --type:2 --value:null
name:aria-valuenow --type:2 --value:
name:aria-selected --type:2 --value:
name:onmouseout --type:2 --value:null
name:aria-owns --type:2 --value:
name:onvolumechange --type:2 --value:null
name:aria-valuemax --type:2 --value:
name:onplaying --type:2 --value:null
name:onmoveend --type:2 --value:null
name:dataFormatAs --type:2 --value:
name:ontimeupdate --type:2 --value:null
name:oncellchange --type:2 --value:null
name:onloadstart --type:2 --value:null
name:aria-valuemin --type:2 --value:
name:onlayoutcomplete --type:2 --value:null
name:onhelp --type:2 --value:null
name:onerrorupdate --type:2 --value:null
name:contentEditable --type:2 --value:inherit
name:ondurationchange --type:2 --value:null
name:onmousedown --type:2 --value:null
name:onwaiting --type:2 --value:null
name:aria-setsize --type:2 --value:0
name:onpaste --type:2 --value:null
name:onmouseleave --type:2 --value:null
name:onselect --type:2 --value:null
name:onclick --type:2 --value:null
name:ondrag --type:2 --value:null
name:aria-controls --type:2 --value:
name:onresizestart --type:2 --value:null
name:aria-flowto --type:2 --value:
name:ondatasetcomplete --type:2 --value:null
name:aria-required --type:2 --value:
name:onended --type:2 --value:null
name:onemptied --type:2 --value:null
name:aria-describedby --type:2 --value:
name:onmouseenter --type:2 --value:null
name:onbeforecut --type:2 --value:null
name:aria-activedescendant --type:2 --value:
name:aria-multiselectable --type:2 --value:
name:onprogress --type:2 --value:null
name:align --type:2 --value:
name:nofocusrect --type:2 --value:null
name:noWrap --type:2 --value:false
复制代码
作者:
一生一世
时间:
2012-6-22 21:52
可是我的输出结果只有一个id属性,并没有这么多的属性呀??这是为什么呢??
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2