好像你有多个相同的
classes
所以使用
$(this)
$('.approve_chk').on('click', function () {
var pswd = prompt("enter password to confirm");
if (pswd == 'approve') {
alert('APPROVED');
} else {
alert('NOT APPROVED');
$(this).prop('checked', false);
}
});
$('.reject_chk').on('click', function () {
var pswd = prompt("enter password to confirm");
if (pswd == 'reject') {
alert('REJECTED');
$(this).closest('tr').find('.approve_chk').prop('checked', false);
} else {
alert('NOT REJECTED');
$(this).prop('checked', false);
}
});
工作段:
$('.approve_chk').on('click', function () {
var pswd = prompt("enter password to confirm");
if (pswd == 'approve') {
alert('APPROVED');
} else {
alert('NOT APPROVED');
$(this).prop('checked', false);
}
});
$('.reject_chk').on('click', function () {
var pswd = prompt("enter password to confirm");
if (pswd == 'reject') {
alert('REJECTED');
$(this).closest('tr').find('.approve_chk').prop('checked', false);
} else {
alert('NOT REJECTED');
$(this).prop('checked', false);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td>
<input type="checkbox" id="approve" class="approve_chk" data-id="1">Approve
</td>
<td>
<input type="checkbox" id="reject" class="reject_chk" data-id="1">Reject
</td>
</tr>
<tr>
<td>
<input type="checkbox" id="approve" class="approve_chk" data-id="2">Approve
</td>
<td>
<input type="checkbox" id="reject" class="reject_chk" data-id="2">Reject
</td>
</tr>
</table>