本文實例講述了JS選中checkbox後獲取table內一行TD所有數據的方法。分享給大家供大家參考。具體實現方法如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Untitled</title> <script> function test(o) { if (!o.checked) { return; } var tr = o.parentNode.parentNode; var tds = tr.cells; var str = "you click "; for(var i = 0;i < tds.length;i++){ if (i < 3) { str = str + tds[i].innerHTML + "--"; } } alert(str); } </script> </head> <body> <table width="60%" cellspacing="0" cellpadding="0" align="left" border="1" bordercolordark="#ffffff" bordercolorlight="#B3B5B4" > <tbody id="tabstore1"> <tr> <td>b1</td> <td>b2</td> <td>b3</td> <td><input type="checkbox" onclick="test(this);"/></td> </tr> <tr> <td>c1</td> <td>c2</td> <td>c3</td> <td><input type="checkbox" onclick="test(this);"/></td> </tr> </tbody> </table> </body> </html>
希望本文所述對大家的javascript程序設計有所幫助。