html代码:
1 <table> 2 <tr> 3 <td><input name='one' type='checkbox' value='1'/></td> 4 <td name="name">张三</td> 5 <td name="age">35</td> 6 <td name="job">职员</td> 7 <td naem="sal">3444</td> 8 </tr> 9 <tr> 10 <td><input name='one' type='checkbox' value='1'/></td> 11 <td name="name">李四</td> 12 <td name="age">34</td> 13 <td name="job">职员</td> 14 <td naem="sal">4555</td> 15 </tr> 16 <tr> 17 <td><input name='one' type='checkbox' value='1'/></td> 18 <td name="name">王二</td> 19 <td name="age">55</td> 20 <td name="job">boss</td> 21 <td naem="sal">10000</td> 22 </tr> 23 </table> 24 <button id="btn" value="submit">submit</button>
js代码:
1 <script src="jquery-2.1.4/jquery.min.js"></script> 2 3 <script> 4 $(document).ready(function () { 5 $("#btn").click(function () { 6 var row; 7 $("input[type='checkbox']").each(function () { 8 if($(this).is(":checked")){ 9 //获取整个表,为下面遍历 10 row = $(this).parent("td").parent("tr"); 11 //比较val(),html(),text()的区别 12 var str = row.html(); 13 var str1 = row.val(); 14 var str2 = row.text(); 15 alert(str); 16 alert(str1); 17 alert(str2); 18 //采用find() childen()方法进行选择 19 var str3 = row.find("td").text(); 20 var str4 = row.find("td").val(); 21 var str5 = row.find("td").html(); 22 alert(str3); 23 alert(str4); 24 alert(str5); 25 var str6 = row.find(".name").text(); 26 var str7 = row.find(".name").val(); 27 var str8 = row.find(".name").html(); 28 alert(str6); 29 alert(str7); 30 alert(str8); 31 } 32 33 }) 34 }) 35 }) 36 </script>