![](/img/trans.png)
[英]Getting data from a specific column in a HTML table when a checkbox in that row is checked using Javascript/JQuery
[英]Loop through table using jQuery, update specific cell in a row with a checked Checkbox
我就是无法解决这个问题。 我有一张带有一列复选框的表格。 更新完Ajax之后,我想使用选中的复选框更新行中的特定单元格。 我正在使用的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
});
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>
Ajax调用成功,但是我的表更新没有发生。
首先,使用类,因为Ids必须是唯一的,如下所示:
<tr>
<td><input type="checkbox" class="CaseID"></td>
<td class="DateUpdated"></td>
</tr>
然后使用类选择器,如下所示:
$.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
});
不需要.each()
循环,至少不需要您的示例代码...类选择器将获取所需的所有元素,而与行无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.