下面是我用于表单的一些脚本。除了最后一次警报外,一切都很好。它指向输入#address_province。如果客户的地址是列表中的其中一个(显示为测试目的是值WA,AL,GA)我想要一个警报,否则他们可以继续。无论我在国家领域投入什么,目前都没有任何反应......无论如何我都可以继续。我究竟做错了什么?
提前谢谢!
<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>
答案 0 :(得分:1)
必须有正确的条件:
if ($('#address_province').val() != "WA") {
修改强>
@jsmorph在评论中指出的主要问题是:
}
if (!$('#address_province').val() == "WA") {
关闭您的功能validateShipping() {
。