Javascript 添加选择表单验证程序
我使用此代码验证输入文本和输入复选框。但我想添加选择框验证所需的功能。我希望用户必须选择一个字符串并选择框填充Javascript 添加选择表单验证程序,javascript,html,Javascript,Html,我使用此代码验证输入文本和输入复选框。但我想添加选择框验证所需的功能。我希望用户必须选择一个字符串并选择框填充 required:{ set:function(val) { //Check the type of the input switch(this.tagName) { case 'INPUT': if($(thi
required:{
set:function(val) {
//Check the type of the input
switch(this.tagName) {
case 'INPUT':
if($(this).attr('type') == 'text') {
val = $.trim(val);
if(val === '') {
return false;
}else {
return true;
}
}else if($(this).attr('type') == 'checkbox') {
return $(this).is(':checked') ? true : false;
}
break;
default:
return false;
break;
}
},
message:'This field is required.'
},
但是我不知道在什么地方添加代码。如果你写了代码,那么你就知道在哪里添加代码如果在else之后再写另一个else如果
else if($(this).attr('type') == 'checkbox') {
return $(this).is(':checked') ? true : false;
}
else if($(this).attr('select') == '') {
if(val === '') {
return false;
}else {
return true;
}
}