0

我正在尝试使用一组多选复选框,但其中一个选项可以是“N/A”。如果选中此项,我希望所有其他人(没有输入-na 类)都未选中。此外,如果选中了非 NA 复选框,我希望取消选中 NA 复选框。

我尝试了以下方法,但其他复选框没有发生任何事情:

<script type="text/javascript">
$(document).ready(function () {
    $("input[type=checkbox].input-na").change(function (event) {
        if ($(this).prop("checked")) {
            $('input[type=checkbox]').not('.input-na').prop('checked', false);
        }
    });

    $("input[type=checkbox]").not(".input-na").change(function (event) {
        if ($(this).prop("checked")) {
            $("input[type=checkbox].input-na").prop("checked", false);
        }
    });
});

它通过“if ($(this).prop("checked"))”进入这两个领域,我已经通过发出警报确认了这一点,所以这是取消选中的实际代码不起作用。

编辑:这是标记:

<fieldset data-role="controlgroup">



    <input type="hidden" name="Questions[0].ResponseOptions[0].key" value="1" />
    <input type="hidden" name="Questions[0].ResponseOptions[0].value.ResponseNum" value="1" />
    <input type="hidden" name="Questions[0].ResponseOptions[0].value.Text" value="Self service gas, paid at the pump" />
    <input type="hidden" name="Questions[0].ResponseOptions[0].value.IsNA" value="False" />

    <input type="checkbox" name="Questions[0].Responses" id="Question_040179122124101173157046112086076030096242133244_1" value="1" 

    />
    <label for="Question_040179122124101173157046112086076030096242133244_1">Self service gas, paid at the pump</label>



    <input type="hidden" name="Questions[0].ResponseOptions[1].key" value="2" />
    <input type="hidden" name="Questions[0].ResponseOptions[1].value.ResponseNum" value="2" />
    <input type="hidden" name="Questions[0].ResponseOptions[1].value.Text" value="Self service gas, paid inside at the kiosk or convenience store" />
    <input type="hidden" name="Questions[0].ResponseOptions[1].value.IsNA" value="False" />

    <input type="checkbox" name="Questions[0].Responses" id="Question_040179122124101173157046112086076030096242133244_2" value="2" 

    />
    <label for="Question_040179122124101173157046112086076030096242133244_2">Self service gas, paid inside at the kiosk or convenience store</label>



    <input type="hidden" name="Questions[0].ResponseOptions[2].key" value="3" />
    <input type="hidden" name="Questions[0].ResponseOptions[2].value.ResponseNum" value="3" />
    <input type="hidden" name="Questions[0].ResponseOptions[2].value.Text" value="Full service provided by attendant" />
    <input type="hidden" name="Questions[0].ResponseOptions[2].value.IsNA" value="False" />

    <input type="checkbox" name="Questions[0].Responses" id="Question_040179122124101173157046112086076030096242133244_3" value="3" 

    />
    <label for="Question_040179122124101173157046112086076030096242133244_3">Full service provided by attendant</label>



    <input type="hidden" name="Questions[0].ResponseOptions[3].key" value="4" />
    <input type="hidden" name="Questions[0].ResponseOptions[3].value.ResponseNum" value="4" />
    <input type="hidden" name="Questions[0].ResponseOptions[3].value.Text" value="Convenience store purchase (not including gas or diesel)" />
    <input type="hidden" name="Questions[0].ResponseOptions[3].value.IsNA" value="False" />

    <input type="checkbox" name="Questions[0].Responses" id="Question_040179122124101173157046112086076030096242133244_4" value="4" 

    />
    <label for="Question_040179122124101173157046112086076030096242133244_4">Convenience store purchase (not including gas or diesel)</label>



    <input type="hidden" name="Questions[0].ResponseOptions[4].key" value="5" />
    <input type="hidden" name="Questions[0].ResponseOptions[4].value.ResponseNum" value="5" />
    <input type="hidden" name="Questions[0].ResponseOptions[4].value.Text" value="Car wash" />
    <input type="hidden" name="Questions[0].ResponseOptions[4].value.IsNA" value="False" />

    <input type="checkbox" name="Questions[0].Responses" id="Question_040179122124101173157046112086076030096242133244_5" value="5" 

    />
    <label for="Question_040179122124101173157046112086076030096242133244_5">Car wash</label>



    <input type="hidden" name="Questions[0].ResponseOptions[5].key" value="6" />
    <input type="hidden" name="Questions[0].ResponseOptions[5].value.ResponseNum" value="6" />
    <input type="hidden" name="Questions[0].ResponseOptions[5].value.Text" value="Washrooms" />
    <input type="hidden" name="Questions[0].ResponseOptions[5].value.IsNA" value="False" />

    <input type="checkbox" name="Questions[0].Responses" id="Question_040179122124101173157046112086076030096242133244_6" value="6" 

    />
    <label for="Question_040179122124101173157046112086076030096242133244_6">Washrooms</label>



    <input type="hidden" name="Questions[0].ResponseOptions[6].key" value="7" />
    <input type="hidden" name="Questions[0].ResponseOptions[6].value.ResponseNum" value="7" />
    <input type="hidden" name="Questions[0].ResponseOptions[6].value.Text" value="None of the above" />
    <input type="hidden" name="Questions[0].ResponseOptions[6].value.IsNA" value="True" />

    <input type="checkbox" name="Questions[0].Responses" id="Question_040179122124101173157046112086076030096242133244_7" value="7" 

                                                                                                        class = "input-na"

    />
    <label for="Question_040179122124101173157046112086076030096242133244_7">None of the above</label>

4

0 回答 0