日期:2014-05-16 浏览次数:20435 次
<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>
------解决方案--------------------
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); }