gpt4 book ai didi

javascript - 复选框在编辑页面中不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 08:38:44 26 4
gpt4 key购买 nike

全选复选框在初始时运行良好。脚步:1.考虑我选中一些复选框或选中所有复选框,然后保存表单2.编辑保存的表格显示没有检查。它在初始阶段显示复选框。没有保存。

Javascript

<%= check_box_tag "box_select_all" %>

<%= check_box_tag "box_id[]", box.id, false, class: 'box_select' %>

jQuery

$('body').delegate('#box_select_all', 'click', function() {
$('.box_select').prop('checked', this.checked);
});


$('body').delegate('.box_select', 'click', function() {
if ($(".box_select").length == $(".box_select:checked").length) {
$("#box_select_all").prop("checked", "checked");
} else {
$("#box_select_all").prop("checked", false);
}
});

谁能帮帮我??

最佳答案

为什么要把那个函数委托(delegate)给 body,当你点击复选框时,函数就会被调用。像这样调用它:

$("#box_select_all").click(function() {
$(".box_select").prop('checked', this.checked);
});

$(".box_select").click(function() {
if ($(".box_select").length == $(".box_select:checked").length) {
$("#box_select_all").prop("checked", "checked");
}
else {
$("#box_select_all").prop("checked", false);
}
});

希望它能奏效。

关于javascript - 复选框在编辑页面中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18141582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com