0

下面是我用于表单的一些脚本。除了最后一个警报外,一切都很好。它指向输入#address_province。如果客户的地址是列表中的地址之一(出于测试目的,显示的是值 WA、AL、GA)我想要一个警报,否则他们可以继续。目前,无论我在 state 字段中输入什么内容,都不会发生任何事情......无论如何我都可以继续。我究竟做错了什么?

先感谢您!

<script>
// Hides shipping info fieldset if ship to billing is checked
$(function () {
    $("#ship_to_billing").change(function () {
        if ($(this).is(":checked")) $("#shipping_info").hide();
        else $("#shipping_info").show();
    });
});

// Validates address fields are filled out unless ship to billing is checked...   
function validateShipping() {
    if (!$("#ship_to_billing").is(":checked")) {
        var inputs = $("#shipping_info input");
        var ready = true;
        inputs.each(function () {
            if ($(this).val() == '') {
                ready = false;
                return false;
            }
        });
        if (!ready) {
            alert("Please tell us where to send this. Either choose ship to Billing Address or fill out both the Recipient Name as well as Shipping Address fields. Thanks!");
            return false;
        }
    }
        // Makes sure age verification is checked 
        if (!$('#age_verification').is(':checked')) {
            alert("Please verify you are 21 years of age or older.");
            return false;       
        }   
    }
       // Confirms province is allowed for wine shipping 
        if (!$('#address_province').val() == "WA") {
            alert("Shipping gifts containing alcohol to this state is prohibited by law. Please choose another item.");
             return false;       
        }
 return true;
}
</script>
4

1 回答 1

1

正确的条件必须是:

if ($('#address_province').val() != "WA") {

编辑

@jsmorph 在评论中指出的主要问题是:

}if (!$('#address_province').val() == "WA") {关闭你的功能之前validateShipping() {

于 2013-09-30T17:38:45.017 回答