js小技巧之访问元素属性


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    
<title>无标题页</title>
</head>
<body>
<div id="roboth"></div>
<script type="text/javascript">
//<![CDATA
//
attributes             elements           NamedNodeMap
var div=document.getElementById("roboth");
alert(div.attributes.getNamedItem(
"id").nodeValue);
alert(div.attributes.item(
0).nodeValue);
alert(div.getAttributeNode(
"id").nodeValue);
alert(div.getAttribute(
"id"))
//]]>
</script>
</body>
</html>

posted @ 2009-05-15 08:41  roboth  阅读(230)  评论(1编辑  收藏  举报