<div class="htmlarea"><textarea id="runcode54928"> <div id="myId" class="cls" userattribute="test1"> <br><input onclick="runEx('runcode54928')" type="button" value="运行代码"><input onclick="doCopy('runcode54928')" type="button" value="复制代码"> <input onclick="doSave(runcode54928)" type="button" value="保存代码"> <a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">[Ctrl A 모두 선택 참고: </a>외부 J를 도입해야 하는 경우 실행하려면 새로 고쳐야 합니다 </div>]<script type="text/javascript"> var div = document.getElementById('myId'); div.userProperty = 'test2'; alert(div.attributes.length); // IE6/7/8 -> 4 , [id,class,userAttribute,userProperty] // IE9/FF -> 3, [id,class,userAttribute] alert(div.userAttribute); // IE6/7/8 -> 'test1' // IE9/FF -> undefined alert(div.getAttribute('userAttribute')); // IE6/7/8/9/FF -> 'test1' alert(div.getAttribute('userProperty')); // IE6/7/8 -> 'test2' // IE9/FF -> null </script></textarea></div>