日期:2014-05-16  浏览次数:20402 次

如何显示表格内容
我有一个table表格,选中某一行后,点击“查看(button)”按钮可以实现对该行内容的显示?如何用JS实现?
请教下高手:)
谢谢!

------解决方案--------------------
HTML code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>newpage</title>
</head>
<body>
<table border="1" width="100%"> 
<tr>  
<td><input type=checkbox></td > 
<td>11111</td  >  
</tr>  
<td><input type=checkbox></td> 
<td>22222</td>
</tr> 
<td><input type=checkbox></td> 
<td>33333</td> 
</tr> 
<td><input type=checkbox></td> 
<td>44444</td> 
</tr> 
<td><input type=checkbox></td> 
<td>55555</td>   
</tr>  
</table>
<input type=button value="查看" onclick=getVal()>
</body>
<script>
function getVal(){
var t=document.getElementsByTagName("table")[0];
for(var i=0;i<t.rows.length;i++){
if(t.rows(i).cells(0).firstChild.checked){
alert("第"+(i+1)+"行已选中,值为:"+t.rows(i).cells(1).innerText);
}
}
}
</script>
</html>

------解决方案--------------------
JScript code

window.onload=function()
{
   var buttons=document.getElementsByTagName("input");
   for(var i=0;i<buttons.length;i++)
   {
      var thisButton=buttons[i];
      if(thisButton.getAttribute("value")=="view")
      {
         thisButton.onclick=function()
         {
            $("divDisplay").innerHTML=this.parentNode.parentNode.innerHTML;
         }
      }
   }
}

function $(objID)
{
   return document.getElementById(objID);
}