我想创建我自己的基本表单验证,而不必诉诸重型的,一刀切的插件,我写了下面的代码。似乎没有多少时间我重写它,并重新开始,我似乎无法让它工作。jquery基本表单验证
这个想法是,脚本检查表单以查看是否所有字段都已完成,如果是,则从提交按钮中删除禁用的属性。
的功能: -
function checkForm(){
$('#contact :input').each(function(){
if($(this).attr('value') == null){
var checked = false;
} else {
var checked = true;
}
})
if (checked == true){
alert('all filled in');
//remove disabled attribute from button
} else {
alert('not completed');
//add disabled attribute to button
}
}
并调用该函数的代码: -
$('#contact :input').blur(function(){
if ($(this).val() <= ''){
$(this).next('.error').show();
} else {
$(this).next('.error').hide();
checkForm();
}
})
我一直是这样折腾了一整天,我在努力找到通过谷歌的答案。
有可能是与你比较'如果($(本).VAL()<= ''){' – TRR