jQuery验证器未返回预期结果
我有一个适合老年人的文本框。提交表单时,我想从客户端检查文本框中的值是否大于18,如果年龄不大于18,则显示消息 我现在遇到的问题是,我的自定义验证器在我键入文本时显示消息,而在我键入18以下的数字时根本不显示消息。感谢您的帮助。多谢各位 这是我的自定义验证器:jQuery验证器未返回预期结果,jquery,Jquery,我有一个适合老年人的文本框。提交表单时,我想从客户端检查文本框中的值是否大于18,如果年龄不大于18,则显示消息 我现在遇到的问题是,我的自定义验证器在我键入文本时显示消息,而在我键入18以下的数字时根本不显示消息。感谢您的帮助。多谢各位 这是我的自定义验证器: <script> $(document).ready(function(){ $.validator.addMethod('ageGreaterEighteen', function(value){
<script>
$(document).ready(function(){
$.validator.addMethod('ageGreaterEighteen', function(value){
return parseFloat(value) > 0;
}, 'Age has to be greater than 18');
$.validator.addMethod("textOnly", function(value) {
return !/[0-9]+/.test(value);
}, "Alpha Characters Only.");
$("#TestForm").validate({
rules: {
txtName: {
required: true,
textOnly: true
},
txtAge: {
required: true,
ageGreaterEighteen: true
}
},
messages: {
txtName: {
required: "* Required",
textOnly: "Please enter text only"
},
txtAge: {
required: "* Required",
ageGreaterEighteen: "Age has to be greater than 18!"
}
}
});
})
</script>
$(文档).ready(函数(){
$.validator.addMethod('agegreater18',函数(值){
返回parseFloat(值)>0;
}“年龄必须大于18岁”;
$.validator.addMethod(“textOnly”,函数(值){
返回!/[0-9]+/.test(值);
},“仅限字母字符。”);
$(“#TestForm”).validate({
规则:{
txtName:{
要求:正确,
纯文本:对
},
txtAge:{
要求:正确,
十八岁以上:对
}
},
信息:{
txtName:{
必需:“*必需”,
textOnly:“请仅输入文本”
},
txtAge:{
必需:“*必需”,
年龄大于18岁:“年龄必须大于18岁!”
}
}
});
})
这是我的表格:
<form id="TestForm">
<label for="txtName">Name: </label><br />
<input name="txtName" type="text" id="txtFirstName" /><br />
<label for="txtAge">Age: </label><br />
<input name="txtAge" type="text" id="txtAge" /><br />
<input type="submit" value="Submit" id="btnSubmit" />
</form>
名称:
年龄:
您有:
$.validator.addMethod('ageGreaterEighteen', function(value){
return parseFloat(value) > 0;
}, '
应该是哪一个
$.validator.addMethod('ageGreaterEighteen', function(value){
return parseFloat(value) > 18;
}, '
不应
返回parseFloat(值)>0
bereturn parseFloat(值)>18代码>?