开发者

How to check if form elements are not empty?

开发者 https://www.devze.com 2022-12-23 02:51 出处:网络
How can I chec开发者_高级运维k if all the elements inside a form \"textbox, checkbox, textarea, select, file\" are not empty? You can see if any are empty like this:

How can I chec开发者_高级运维k if all the elements inside a form "textbox, checkbox, textarea, select, file" are not empty?


You can see if any are empty like this:

$(":input").each(function() {
   if($(this).val() === "")
    alert("Empty Fields!!");
});

You can read on the :input selector here

for a more specific answer, if you only want those types, change the selector like this:

$(":text, :file, :checkbox, select, textarea").each(function() {
   if($(this).val() === "")
    alert("Empty Fields!!");
});
0

精彩评论

暂无评论...
验证码 换一张
取 消