Check all input fields have been filled out with jQuery

前端 未结 4 1060
轻奢々
轻奢々 2020-12-08 14:12

I have 3 divs, each with a dfew input fields and next button on. I want to write a snippet of jQuery that when the next button is clicked it checks to ensure all input fiel

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 14:59

    $('.next').click(function() {
        var emptyInputs = $(this).parent().find('input[type="text"]').filter(function() { return $(this).val() == ""; });
        if (emptyInputs.length) {
            alert('Fail!');
        }
    });
    

提交回复
热议问题