How to check if all inputs are not empty with jQue

2019-01-18 02:12发布

I need to validate a form with jQuery. I can check all my inputs one by one, but it's not a very practical solution.

How can i check if all my inputs are non-empty more efficiently? In my form i can have input elements of different types: text, several groups of radio, select etc.

标签: jquery input
8条回答
叛逆
2楼-- · 2019-01-18 03:01
var isValid = true;
$("#tabledata").find("#tablebody").find("input").each(function() {
var element = $(this);
if (element.val() == "") {
isValid = false;
}
else{
isValid = true;
}
}); 
console.log(isValid);
查看更多
相关推荐>>
3楼-- · 2019-01-18 03:02
$('#form_submit_btn').click(function(){
    $('input').each(function() {
        if(!$(this).val()){
            alert('Some fields are empty');
           return false;
        }
    });
});
查看更多
登录 后发表回答