日期:2014-05-17  浏览次数:20772 次

表格行数不确定,如何为表格最后一行指定样式?
如题

------解决方案--------------------
用javascript
------解决方案--------------------
<html>
<head> <title> 测试 </title> </head>
<style type= "text/css ">
.bb{
border-color:red;
}
</style>
<body>
<table width=200 border=1 height=300 cellpadding=0 cellspacing=0 id= "tb1 ">

<tr> <td> &nbsp;DDD </td> <td> &nbsp;bbb </td> </tr>
<tr> <td> &nbsp;ddd </td> <td> &nbsp;BBB </td> <tr>
<tr> <td > &nbsp;CCC </td> <td> &nbsp;AAA </td> <tr>
</table>
<input type= "button " value= "给表格最后一行设置样式 " id= "btn1 ">
<script>
document.all.btn1.onclick=function(){
var tb1=document.getElementById( "tb1 ");
alert(tb1.lastChild.lastChild.previousSibling.innerHTML);
if(tb1.lastChild.lastChild.previousSibling){
alert(tb1.lastChild.lastChild.previousSibling.childNodes.length);
for(i=0;i <tb1.lastChild.lastChild.previousSibling.childNodes.length;i++)
{
alert(tb1.lastChild.lastChild.previousSibling.childNodes[i].innerText);
tb1.lastChild.lastChild.previousSibling.childNodes[i].className= "bb ";

}
}
}
</script>
</body>
</html>