SoFunction
Updated on 2025-03-04

jQuery gets the value of a field in the current row selected by the check box

I won’t say much nonsense, I will just post the code to you. The specific code is as follows:

 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <title>js</title>
 </head>
<script src="js/"></script>
<script language="javascript">
 function getTDtext() 
 {
 var a = ("r");//Get so check box//The first method: determine the parent node of the selected check box through the checked attribute, and use children[index] to get the content of the index child node td/** for(var i=0;i<;i++){
  if(a[i].checked){
    var tddata=a[i].[1].innerHTML;
    alert(tddata);
  }
} **/
//The second method: determine the parent node of the selected checkbox through the checked attribute, traverse the child node td under the parent node, and obtain the content under the td when the name of td is equal to a certain value,for(var i=0;i<;i++){
if(a[i].checked){
  var tddata=a[i].;
  $(tddata).find("td").each(function(){
    if(("name")=="z"){
      alert();
    }
  });
}
}
}
 </script>
 <body>
 <table >
 <tr><td><input type="checkbox" name="r" value="1"></td><td name="z">a</td><td name="x">b</td></tr>
 <tr><td><input type="checkbox" name="r" value="2"></td><td name="z">b</td><td name="x">b</td></tr>
 <tr><td><input type="checkbox" name="r" value="3"></td><td name="z">c</td><td name="x">b</td></tr>
 <tr><td><input type="checkbox" name="r" value="4"></td><td name="z">d</td><td name="x">b</td></tr>
 <tr><td><input type="checkbox" name="r" value="5"></td><td name="z">e</td><td name="x">b</td></tr>
 <tr><td><input type="checkbox" name="r" value="6"></td><td name="z">f</td><td name="x">b</td></tr>
 </table>
 <input type="button" onclick="getTDtext()" value="button"/>
</body>
</html>

Summarize

The above is the value of a field in the current row selected by the jQuery check box introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!