The example of this article describes the method for selecting the whole row data of the checkbox by JS. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>js</title>
<script language= "JavaScript" >
function Gettdtext ()
{
var rows = document.getElementById ("test_table"). Rows;
var a = Document.getelementsbyname ("R");
var states = "";
var table = document.getElementById ("test_table");
for (Var i=0;i<a.length;i++)
{
if (a[i].checked) {
var row = A[i].parentelement.parentelement.rowindex ;
//states + + rows[row].cells[1].innerhtml+ ";";
alert (a[i].value);
alert (rows[row].cells[1].innerhtml);
}
}
}
</script>
<body>
<table id= "Test_table" >
<tr><td><input type= "checkbox" Name= "R" value= "1" ></td><td>a</td></tr>
<tr><td><input type= "checkbox" Name= "R" value= "2" ></td><td>b</td></tr>
<tr><td><input type= "checkbox" Name= "R" value= "3" ></td><td>c</td></tr>
<tr><td><input type= "checkbox" Name= "R" value= "4" ></td><td>d</td></tr>
<tr><td><input type= "checkbox" Name= "R" value= "5" ></td><td>e</td></tr>
<tr><td><input type= "checkbox" Name= "R" value= "6" ></td><td>f</td></tr>
</table>
<input type= "button" onclick= "Gettdtext ()" value= "button" >
</body>
I hope this article will help you with your JavaScript programming.