【发布时间】:2021-09-27 00:08:29
【问题描述】:
代码仅在一个文本框上显示所需的消息,但我想在每个复选框上显示所需的消息。
它提交表单而不检查所需的验证,只有第一个选中的文本框显示验证,当我选中该框时它没有删除验证。它仍然显示验证消息。
有什么解决办法吗?提前致谢
<div class="row" id="addform_allowances"></div>
$('#add_button').click(function() {
$('#hrm_employeeDesignation').html("");
//designations dropdown
$.ajax({
url: 'api/Hrm/hrm_payscales_api.php',
type: 'POST',
data: {
action: 'designations'
},
success: function(response) {
$('#hrm_employeeDesignation').append($('<option disabled selected>Choose Option</option>'));
for (var i = 0; i < response.length; i++) {
$('#hrm_employeeDesignation').append($('<option>', {
value: response[i].ID,
text: response[i].NAME
}));
}
},
error: function(e) {
console.log(e);
alert("Contact IT Department");
}
});
//allowances dropdown
$.ajax({
url: 'api/Hrm/hrm_payscales_api.php',
type: 'POST',
data: {
action: 'activeallowances'
},
success: function(response) {
for (var i = 0; i < response.length; i++) {
console.log(response[i].ALLOWANCE);
var append_allowances = "<div class='col-md-6 form-group'><input name='allowanceid[]' id='checkbox" + i + "'
type = 'checkbox'
value = '"+response[i].ID+"' > < label
for = '' > & nbsp; & nbsp;
"+response[i].ALLOWANCE+": < /label><input
id = 'amountcheckbox"+i+"'
type = 'number'
name = 'allowance_amount[]'
class = 'allowance_amount'
disabled > < /div>";
$('#addform_allowances').append(append_allowances);
}
},
error: function(e) {
console.log(e);
alert("Contact IT Department");
}
});
});
$('#addform_allowances').on('click', 'input[type=checkbox]', function() {
var checkboxidattr = $(this).attr("id");
if ($('input[type=checkbox][id=' + checkboxidattr + ']').is(':checked')) {
$('#amount' + checkboxidattr + '').attr('required', 'required');
$('#amount' + checkboxidattr + '').removeAttr('disabled');
} else {
$('#amount' + checkboxidattr + '').removeAttr('required');
$('#amount' + checkboxidattr + '').attr('disabled');
$('#amount' + checkboxidattr + '').val('');
}
});
【问题讨论】: