获取< td>值仅在使用jQuery的特定行中 [英] Get <td> values only in specific rows using jQuery
本文介绍了获取< td>值仅在使用jQuery的特定行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表(id ="docsTable"),其行看起来与此类似:
I have a table (id="docsTable") whose rows look similar to this:
<tr bgcolor="#E7DDCC">
<td align="center"><input type="checkbox" name="docsToAddToClass[]" value="35" /></td>
<td>Document Title</td>
<td>Document Description.</td>
</tr>
我需要遍历表,确定用户已经选中了哪些复选框,对于带有选中复选框的行,获取第一个值和接下来两个的文本.
I need to iterate through the table, determine which checkboxes the user has checked, and for the rows with a checked checkbox, grab the value for the first and the text for the next two.
我不需要构建集合:在每次迭代中,我想更改其他地方的某些元素. (对我而言)这不是困难的部分.它试图找出如何遍历表格并仅选中带有选中复选框的.
I don't need to build a collection: Within each iteration I want to change some elements elsewhere. That's not the hard part (for me). It's trying to figure out how to iterate through the table and select only the s with checked checkboxes.
推荐答案
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
<script type="text/javascript">
$(function(){
$('#btnTest').click(function(){
$('#docsTable input[type="checkbox"]:checked').each(function(){
var $row = $(this).parents('tr');
alert($row.find('td:eq(0) input').val());
alert($row.find('td:eq(1)').html());
alert($row.find('td:eq(2)').html());
});
});
});
</script>
</head>
<body>
<table id="docsTable">
<tr bgcolor="#E7DDCC">
<td align="center"><input type="checkbox" name="docsToAddToClass[]" value="35" /></td>
<td>Document Title 1</td>
<td>Document Description.</td>
</tr>
<tr bgcolor="#E7DDCC">
<td align="center"><input type="checkbox" name="docsToAddToClass[]" value="36" /></td>
<td>Document Title 2</td>
<td>Document Description.</td>
</tr>
<tr bgcolor="#E7DDCC">
<td align="center"><input type="checkbox" name="docsToAddToClass[]" value="37" /></td>
<td>Document Title 3</td>
<td>Document Description.</td>
</tr>
</table>
<input type='button' id='btnTest' value='Get Rows' />
</body>
</html>
这篇关于获取< td>值仅在使用jQuery的特定行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文