我正在尝试验证一个接收用户邮政编码的表单,并针对所服务的邮政编码数组进行测试。我想让它在提交时工作。现在它什么也不做,也没有抛出任何错误。我很迷茫。我是 jquery 的新手,但不会编程
<DOCTYPE!>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
var zipCodeArray = ["98001", "98002", "98003", "98004"];
$("#zipCode").live('keyup', function(){
var zipCode = $(this).val();
if(zipCode.length >4){
if($.inArray(zipCode, zipCodeArray)){
//do nothing, or do whatever you want
//we have a return true here.
}else{
alert("Sorry. we only offer services western Washington at this time.");
}
}
});
</script>
</head>
<body>
<div class="zipCode">
<form>
<input id="zipCode" name="zipCode" />
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>