Javascript 当我通过jQuery删除attr时,我可以';不要再添加属性

Javascript 当我通过jQuery删除attr时,我可以';不要再添加属性,javascript,jquery,attributes,attr,Javascript,Jquery,Attributes,Attr,这是我的代码: $("input[name=donationmode]").change(function() { $(".setpaymentOptions").children().addClass("fadeout"); $(".setpaymentOptions").children().children(".inputfield").children("input").attr("disabled", "disabled"); $(".option-"+$(t

这是我的代码:

$("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不会返回


请帮帮我,bug在哪里?

如果不想添加onclick属性,则需要添加处理程序(并使用删除)

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

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