这是我的代码:

$("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的返回时,onclick不会返回。

请帮助我,错误在哪里?

有帮助吗?

解决方案

您不想添加一个单击属性,您想添加一个 点击 处理程序(并使用 解开).

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

   $('.option-2').find('.addPaymentOption').unbind( 'click', addPaymentOption );
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top