【发布时间】:2015-11-18 10:18:29
【问题描述】:
我在模态弹出窗口中动态填充一些文本框,提交表单时我需要检查必填字段是否已填写。
我尝试了两种方法,但都不起作用..
如果你想检查这里是完整的代码 http://jsfiddle.net/nsk21/f52nLfrj/
这是如何尝试1:
$(document).on('click', '#catSave', function(){
var countValid = 0 ;
totRequFileds = 0;
$('#catCreatForm').find('input').each(function(){
alert($(this).attr('type'));
if(!$(this).prop('required')){
if ( this.value.trim() !== '' ) {
countValid++;
}else{
$(this).focus();
return false;
}
totRequFileds++;
} else {
}
});
alert(' totRequFileds:'+totRequFileds +' | '+countValid);
});
尝试 2:
$( ':input[required]', '#catCreatForm' ).each( function () {
alert($(this).attr('name'));
if ( this.value.trim() !== '' ) {
countValid++;
}else{
$(this).focus();
return false;
}
totRequFileds++;
});
【问题讨论】:
-
你正在处理 Jquery 并且在你的小提琴中它不包含一个库
-
@underscore 这里是更新版本jsfiddle.net/nsk21/f52nLfrj/1