[英]Loop through table using jQuery, update specific cell in a row with a checked Checkbox
I just can't work this one out. 我就是无法解决这个问题。 I have a table with a column of checkboxes.
我有一张带有一列复选框的表格。 After an Ajax update, I want to update a specific cell in the rows with checked checkedboxes.
更新完Ajax之后,我想使用选中的复选框更新行中的特定单元格。 The jQuery Ajax call I'm using is:
我正在使用的jQuery Ajax调用是:
$.ajax({
type: 'POST',
url: 'ProcessDate',
data: params,
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
},
success: function(html) {
closeDialog();
$('#results tbody tr').each(function(){
$("#CaseID:checked").parent().siblings("td.DateUpdated").html('CHANGE');
});
},
cache: false
});
And the HTML is: HTML是:
<table id="results">
<tr>
<td><input type="checkbox" id="CaseID"></td>
<td id="DateUpdated"></td>
</tr>
<tr>
<td><input type="checkbox" id="CaseID"></td>
<td id="DateUpdated"></td>
</tr>
<tr>
<td><input type="checkbox" id="CaseID"></td>
<td id="DateUpdated"></td>
</tr>
The Ajax call succeeds but my table update doesn't happen. Ajax调用成功,但是我的表更新没有发生。
First, use classes since Ids must be unique, like this: 首先,使用类,因为Ids必须是唯一的,如下所示:
<tr>
<td><input type="checkbox" class="CaseID"></td>
<td class="DateUpdated"></td>
</tr>
Then use class selectors, like this: 然后使用类选择器,如下所示:
$.ajax({
type: 'POST',
url: 'ProcessDate',
data: params,
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
},
success: function(html) {
closeDialog();
$(".CaseID:checked").parent().siblings("td.DateUpdated").html('CHANGE');
},
cache: false
});
There's no need for a .each()
loop, at least not with your example code...the class selector will get all the elements you want, regardless of the row. 不需要
.each()
循环,至少不需要您的示例代码...类选择器将获取所需的所有元素,而与行无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.