Home  >  Article  >  Web Front-end  >  How to get all the data of a row of TD in the table after JS selects the checkbox_javascript skills

How to get all the data of a row of TD in the table after JS selects the checkbox_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:51:491793browse

The example in this article describes the method of obtaining all the data of a row of TD in the table after JS selects the checkbox. Share it with everyone for your reference. The specific implementation method is as follows:

<!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>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn