如果没有填写e_usagelow字段,以下jQuery验证代码应该检查用户必须输入e_usage字段的表单。我根据{{3的示例编写了电子使用的依赖调用函数但是不知怎的,我的函数不起作用(例如,当e_usagelow为空时将鼠标放在电子使用字段上时,不会出现验证错误警告,并且控制台显示值'true')
出了什么问题?
请你的帮助。
html代码:
E-usage: <input id="e_usage" type="text" name="e_usage">
E-usage low: <input id="e_usagelow" type="text" name="e_usagelow" >
javascript代码:
$(document).ready(function () {
$("#myForm").validate({
rules: {
'e_usage': {
required: function (element) {
console.log("validation: required: " + $("#e_usagelow").is(':empty'));
return $("#e_usagelow").is(':empty');
},
minlength: 3,
maxlength: 8,
number: true
},
'e_usagelow': {
required: true,
minlength: 3,
maxlength: 8,
number: true
}
} //rules
}); //validate()
}); //function
答案 0 :(得分:0)
将'e_usage'
更改为e_usage
和'e_usagelow'
到e_usagelow
id
未附在引号
$(document).ready(function () {
$("#myForm").validate({
rules: {
e_usage: { //removed quotes from id
required: function (element) {
console.log("validation: required: " + $("#e_usagelow").is(':empty'));
return $("#e_usagelow").is(':empty');
},
minlength: 3,
maxlength: 8,
number: true
},
e_usagelow: { //removed quotes from id
required: true,
minlength: 3,
maxlength: 8,
number: true
}
} //rules
}); //validate()
});