我有一个使用的类型列表和一个复选框 当 Select Change the Value时,我调用一个AJAX来加载值状态并更改复选框
$('input[name=status]').on('change', function() {
$.ajax({
// Do ajax call update
success: function (data) {
// show alert
}
})
});
$('select').on('change', function() {
$.ajax({
// Do ajax call load value
success: function (data) {
// load the data current status to the checkbox
// $('input[name=status]').attr('checked', data.checked); This not work after click checkbox for change
$('input[name=status]').prop('checked', data.checked); // This call event onChange and show the alert
}
})
});
问题是
- 当我使用attr更新更改后的复选框值时,如果我选中了更新当前 Select 类型的状态的复选框.如果我再更改 Select ,则复选框不能更改.
- 我使用属性替换属性它现在起作用了,但新的问题是它将调用CheckBox Change事件,这使alert 显示每个更改的 Select 值.
如果使用复选框props 更改,如何防止事件更改?