</form> </body> </html> <script> function test1() { var aaa = document.getElementById("aa"); for(i in aaa) { if(i=='id') { alert("有id属性"); break; }
} }</script> 用这个
看这:https://developer.mozilla.org/Talk:En/DOM/Element.getAttribute Firefox and Safari both return null when the attribute is inexistent or missing. Internet Explorer 6's behavior is unfortunately a little more erratic. Opera conformed to the specs until version 9 which also returns null.
<head>
<title></title>
</head>
<body>
<form id="formid" action="index.html">
<input name="aa" id="aa">
<input type="button" name="qq" id="qq" onclick="test1()" value="test">
</form>
</body>
</html>
<script>
function test1()
{
var aaa = document.getElementById("aa");
for(i in aaa)
{
if(i=='id')
{
alert("有id属性");
break;
}
}
}</script>
用这个
Firefox and Safari both return null when the attribute is inexistent or missing.
Internet Explorer 6's behavior is unfortunately a little more erratic.
Opera conformed to the specs until version 9 which also returns null.
<script language="javascript">
<!--
var element=document.getElementById("ttt")
alert(typeof(element.caiying2009))
alert(element.getAttribute("caiying2009"))
//-->
</script>ie6-ok