我相信prop(“checked”,{value})不会触发change事件,您还需要添加trigger(“change”)
$(function() {
$("#slider-range").slider({
range: true,
min: 50,
max: 54,
values: [50, 54],
stop: function(event, ui) {
var selected = [];
$('input:checkbox[name=temple]').prop("checked", false);
$("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);
for (var i = ui.values[0]; i <= ui.values[1]; i++) {
selected.push(i);
}
$.each(selected, function(index, value) {
$("input:checkbox[name=temple][value=" + value + "]").prop("checked", true);
$("input:checkbox[name=temple][value=" + value + "]").trigger("change");
})
}
});
$("#amount").val("$" + $("#slider-range").slider("values", 0) +
" - $" + $("#slider-range").slider("values", 1));
$('input:checkbox[name=temple]').on('change', function() {
if ($(this).prop("checked")){
console.log('Checked');
} else {
console.log('Un Checked');
}
});
});