2

これは私のコードです:

$("input[name=donationmode]").change(function() {
    $(".setpaymentOptions").children().addClass("fadeout");
    $(".setpaymentOptions").children().children(".inputfield").children("input").attr("disabled", "disabled");

    $(".option-"+$(this).val()).removeClass("fadeout");
    $(".option-"+$(this).val()).children(".inputfield").children("input").removeAttr("disabled");

    if($(this).val() == 2)
    {
        $(".option-2").children(".inputfield").children("#paymentOption").find("input").removeAttr("disabled");
        $(".option-2").find(".addPaymentOption").attr("onclick", "addPaymentOption()");

    }
    else
    {
        $(".option-2").children(".inputfield").children("#paymentOption").find("input").attr("disabled", "disabled");
        $(".option-2").find(".addPaymentOption").removeAttr("onclick");
    }
});

入力 (3 つのラジオ ボタンのラジオ ボタン グループ) を 2 に変更すると、onclick が .addPaymentOption に追加されます。次に、入力を 3 に変更すると、onclick が消えます。それは良い。

ここで注意が必要なのは、値 2 の the をクリックして戻すと、onclick が戻ってこないことです。

助けてください、バグはどこにありますか?

4

1 に答える 1

8

onclick 属性を追加したくない場合は、クリックハンドラーを追加します (そしてunbindを使用して削除します)。

   $('.option-2').find('.addPaymentOption').click( addPaymentOption );

   $('.option-2').find('.addPaymentOption').unbind( 'click', addPaymentOption );
于 2010-06-04T20:44:44.263 に答える