0

我有一些 jquery 可以防止在选中复选框时更改几个选择字段。这工作正常,但我似乎无法让 unbind 工作。当复选框未选中时,我需要选择再次工作。

$("input#same").live('click', function () {
    if ($("input#same").is(':checked')) {
        // Checked, copy values 
        $("input#shipping_first_name").val($("input#first_name").val()).attr("readonly", true);
        $("input#shipping_last_name").val($("input#last_name").val()).attr("readonly", true);
        $("input#shipping_address").val($("input#address").val()).attr("readonly", true);
        $("input#shipping_address2").val($("input#address2").val()).attr("readonly", true);
        $("input#shipping_city").val($("input#city").val()).attr("readonly", true);
        $("select#shipping_state").val($("select#state").val()).bind("change", function () {
            $("select#shipping_state").val($("select#state").val())
        });
        $("input#shipping_zip").val($("input#zip").val()).attr("readonly", true);
        $("select#shipping_country_code").val($("select#country_code").val()).bind("change", function () {
            $("select#shipping_country_code").val($("select#country_code").val())
        });
    } else {
        // Clear on uncheck 
        $("input#shipping_first_name").val("").removeAttr("readonly");
        $("input#shipping_last_name").val("").removeAttr("readonly");
        $("input#shipping_address").val("").removeAttr("readonly");
        $("input#shipping_address2")..val("").removeAttr("readonly");
        $("input#shipping_city").val("").removeAttr("readonly");
        $("select#shipping_state").val("").unbind("change");
        $("input#shipping_zip").val("").removeAttr("readonly");
        $("select#shipping_country_code").val("").unbind("change");
    }
});
$('#order').live('submit', function () {
    $('input[type=submit]', this).attr('disabled', 'disabled');
});
});
4

1 回答 1

1

使用 live 附加事件时使用 .die()。请参考这里:http ://api.jquery.com/die/

于 2011-01-18T13:46:08.737 回答