Jquery 选择验证
我正在尝试验证此选择/下拉列表。我没有收到错误,但验证没有发生。我正在使用其他字段的验证,效果很好。这是我的 jquery 和似乎不想验证的选择:
$().ready(function() {
$("#cancelForm").validate({
debug: false,
errorClass: "authError",
errorElement: "span",
rules: {
inputString: "required",
notes: "required",
end_time: {required: true}
},
messages: {
inputString: "Please enter the membername",
notes: "Please enter the notes",
end_time: "Please select a time"
}
});
});
这是我的选择:
<div class="styled-select">
<select name="end_time" id="end_time">
<option value="">None</option>
<option value="05:00:00">5:00AM</option>
<option value="05:30:00">5:30AM</option>
</select>
</div>
提前感谢您查看我的问题。
I am trying to validate this select / drop down. I am not getting an error, but the validation is not ocurring. I am using the validation for other fields, which is working fine. Here is my jquery and the select which doesnt want to seem to validate:
$().ready(function() {
$("#cancelForm").validate({
debug: false,
errorClass: "authError",
errorElement: "span",
rules: {
inputString: "required",
notes: "required",
end_time: {required: true}
},
messages: {
inputString: "Please enter the membername",
notes: "Please enter the notes",
end_time: "Please select a time"
}
});
});
Here is my select:
<div class="styled-select">
<select name="end_time" id="end_time">
<option value="">None</option>
<option value="05:00:00">5:00AM</option>
<option value="05:30:00">5:30AM</option>
</select>
</div>
Thanks in advance for taking a look at my issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要写 end_time: {required: true},而是这样写:
并添加此自定义验证方法:
Instead of end_time: {required: true}, write this:
And add this custom validation method:
我认为您不能在选择上使用
required: true
。因为即使该值为空,也总是会选择某些内容。也许尝试
minlength:1
I don't think you can use
required: true
on a select. Because there is always something selected, even if the value is empty.Maybe try
minlength:1