Select multiple ID's - Both checkboxes must be selected

前端 未结 7 898
猫巷女王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 03:59

    I would give the checkboxes a common class. Then use that as the selector and count the checked values. Then if two are checked do something. If one is checked then check the value of that one and do what you need to accordingly.

    EDIT: So say for instance you assigned a common class of myCheckBoxes

    So you could do the following pseudo code:

    var myCheckBoxes = $('.myCheckBoxes:checked') //not sure on selector
    
    if (myCheckBoxes.length == 2)
        //do something because both are checked
    else if (myCheckBoxes.length == 1)
    {
        if (myCheckBoxes.val() == "A")
            // do something because A was checked
        else if (myCheckBoxes.val() == "B")
            // do something because B was checked
    }
    

提交回复
热议问题