<table id="tbl">
<tr><td>hello</td><td>world</td></tr>
<tr width='95%' height='20'><td>hello</td><td>world</td></tr>
<tr width='95%' height='20'><td>hello</td><td>world</td></tr>
</table>
<input type="button" value="show Att" onclick="showAtt()"><script language="javascript">
function showAtt()
{
var row = document.all("tbl").rows[0]; //second row
var width = row.getAttribute("width");
var height = row.getAttribute("height"); if (width)
alert("we have a width attribute, its value:" + width);
else
alert("we don't have a width attribute");
if (height)
alert("we have a height attribute, its value::" + height);
else
alert("we don't have a height attribute");
}
</script>
<tr><td>hello</td><td>world</td></tr>
<tr width='95%' height='20'><td>hello</td><td>world</td></tr>
<tr width='95%' height='20'><td>hello</td><td>world</td></tr>
</table>
<input type="button" value="show Att" onclick="showAtt()"><script language="javascript">
function showAtt()
{
var row = document.all("tbl").rows[0]; //second row
var width = row.getAttribute("width");
var height = row.getAttribute("height"); if (width)
alert("we have a width attribute, its value:" + width);
else
alert("we don't have a width attribute");
if (height)
alert("we have a height attribute, its value::" + height);
else
alert("we don't have a height attribute");
}
</script>
<tr id=abc width=80 height=40 tt=200>
<td>tr中的tt是一个自定义属性</td>
</tr>
</table>
<script>
for(var e in abc){
document.write(e + "<BR>")
// 要直接访问属性,你就用 alert(abc.width); alert(abc.tt); alert(abc.height)
}
</script>
多谢feijunjun(军仔):
for(var e in abc) { //
加分加分