Javascript jQuery复选框在屏幕上保持选中状态

Javascript jQuery复选框在屏幕上保持选中状态,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我的问题是,当我单击其中一个复选框时,它会一直保持打开(选中),直到再次单击屏幕上的任何位置 然而,这被证明是不可复制远离我的完整网页。还有什么可能会干扰?哪些检查/控制台日志可能会有所帮助 选中区域2后,再次单击该区域将不选中,但屏幕上的按钮仍高亮显示。当我点击屏幕上其他地方时,Zone2按钮将不亮 样式也来自jQueryUI 动态生成的HTML <form id="ZoneButtonsForm"> <span id="ButtonsetZone1">

我的问题是,当我单击其中一个复选框时,它会一直保持打开(选中),直到再次单击屏幕上的任何位置

然而,这被证明是不可复制远离我的完整网页。还有什么可能会干扰?哪些检查/控制台日志可能会有所帮助

选中区域2后,再次单击该区域将不选中,但屏幕上的按钮仍高亮显示。当我点击屏幕上其他地方时,Zone2按钮将不亮

样式也来自jQueryUI

动态生成的HTML

<form id="ZoneButtonsForm">
    <span id="ButtonsetZone1">
         <input type="checkbox" id="ButtonZone1" name="zone1" checked>
         <label for="ButtonZone1">Zone 1</label>
    </span>
    <span id="ButtonsetZone2">
        <input type="checkbox" id="ButtonZone2" name="zone2">
        <label for="ButtonZone2">Zone 2</label>
    </span>
    <span id="ButtonsetZone3">
        <input type="checkbox" id="ButtonZone3" name="zone3">
        <label for="ButtonZone3">Zone 3</label>
    </span>                 
</form>

是否您正在将事件处理程序连接到文档的更改事件,而不是单击特定的复选框,并且由于修改任何复选框的选中状态都符合更改文档的条件,因此所有按钮集都会刷新?我无法复制:@Scott我正在使用标准事件委派来处理动态内容,页面上的其他内容不会被重置,@Barmar,这就是问题所在,您的网页上的其他内容正在干扰。最好的工具是在开发者工具中使用
属性更改时中断
$( "#ButtonsetZone1").buttonset({
    items: "input[type=checkbox]"
});
$( "#ButtonsetZone2").buttonset({
    items: "input[type=checkbox]"
});
$( "#ButtonsetZone3").buttonset({
    items: "input[type=checkbox]"
});


$(document).on("change", "#ZoneButtonsForm input[type=checkbox]", function () {//event delegation bind
    console.log("the zone button has been clicked");

    $( "#ButtonsetZone1").buttonset("refresh");
    $( "#ButtonsetZone2").buttonset("refresh");
    $( "#ButtonsetZone3").buttonset("refresh");

               if ($("#defIndividualButtonZone1").is(":checked")){
                    console.log("zone 1 is checked");
                }else{
                    console.log("zone 1 is NOT checked");
                }
                if ($("#defIndividualButtonZone2").is(":checked")){
                    console.log("zone 2 is checked");
                }else{
                    console.log("zone 2 is NOT checked");
                }
                if ($("#defIndividualButtonZone3").is(":checked")){
                    console.log("zone 3 is checked");
                }else{
                    console.log("zone 3 is NOT checked");
                }


});