使用 jQuery 仅获取特定行中的 值
我有一个表(id =“docsTable”),其行看起来与此类似:
<tr bgcolor="#E7DDCC">
<td align="center"><input type="checkbox" name="docsToAddToClass[]" value="35" /></td>
<td>Document Title</td>
<td>Document Description.</td>
</tr>
我需要遍历表,确定用户选中了哪些复选框,对于选中复选框的行,获取第一个的值和后两个的文本。
我不需要构建一个集合:在每次迭代中我想在其他地方更改一些元素。这不是困难的部分(对我来说)。它试图弄清楚如何迭代表并仅选择选中复选框的 s。
<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)
|