2

次のようにaspコントロールをセットアップしています。

<asp:CheckBoxList runat="server" ID="toppingsCheckBoxList">
                        <asp:ListItem type="checkbox" name="toppings" value="pickles" class="toppings">pickles</asp:ListItem>
                        <asp:ListItem type="checkbox" name="toppings" value="lettuce" class="toppings">lettuce</asp:ListItem>
                        <asp:ListItem type="checkbox" name="toppings" value="tomato" class="toppings">tomato</asp:ListItem>
                        <asp:ListItem type="checkbox" name="toppings" value="none" ID="none">none</asp:ListItem>
                    </asp:CheckBoxList> 

また、過去に標準のHTMLコントロールで行った方法でJqueryを介してチェックボックスを無効にしようとしましたが、aspコントロールではそれほど簡単には機能しません。

これまでの私の努力は次のとおりです。

//Jquery for topping disabling/enabling
            $(document).ready(function () {
                //disable toppings when none is selected
                $('#none').click(function () {
                    if ($("#none").selector) {
                        $(".toppings").prop("disabled", true);
                    }else
                        $(".toppings").prop("disabled", false);
                });
                //disable none when a topping is selected
                $(".toppings").click(function () {
                    $(".toppings").each(function (index, element) {
                        if (element.selector && !$("#none").selector) {
                            $("#none").prop("disabled", true);
                        }
                    });
                });
                //enable none when no topping is selected
                $(".toppings").click(function () {
                    var count = 0;
                    $(".toppings").each(function (index, element) {
                        if (!element.selector && index in [0, 1, 2]) {
                            count++;
                        }
                    });
                    if (count == 3) {
                        $("#none").prop("disabled", false);
                    }
                });
            });

ご覧のとおり、.checked を .selector に変更して何がチェックされているかを確認できることがわかりましたが、実際には listitem のチェックボックスをクラス名で無効に変更するのは難しいことがわかりました。私はasp.netの経験があまりないので。

ありがとう!

4

2 に答える 2

0

仕事を辞めようとしているので、これを試すのに十分な時間がありませんが、実装方法のガイドとしてこれを試すことができます:

$('#none').on("change", function () {
    if($('#none').attr("disabled") == false){
        $(".toppings").attr("disabled", true);
    }
    else
        $(".toppings").attr("disabled", false);
});
于 2013-08-21T21:39:39.263 に答える