Select multiple ID's - Both checkboxes must be selected

前端 未结 7 893
猫巷女王i
猫巷女王i 2021-02-07 03:37

Is there a way for two or more ID\'s be required to be checked before doing something.

For instance:

If BOTH Checkbox 1 and Checkbox 2 are checked then th

7条回答
  •  长发绾君心
    2021-02-07 04:11

    $(document).ready(function() {
       var check1 = $("#check1");
       var check2 = $("#check2");
    
       // this method decides what to do when a checkbox is clicked
       var trigger_event = function() {
            if (check1.attr("checked") && check2.attr("checked")) {
                event1();
            }
            else if (check1.attr("checked") && !check2.attr("checked")) {
                event2();
            }
            else if (!check1.attr("checked") && check2.attr("checked")) {
                event3();
            }
       };
    
       // append event
       check1.click(function() {
           trigger_event();
       });
    
       check2.click(function() {
          trigger_event();
       });
    
    };
    

提交回复
热议问题