如何检查表单元素是否为空? [英] How to check if form elements are not empty?

查看:167
本文介绍了如何检查表单元素是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查表单textbox,checkbox,textarea,select,file中的所有元素是否都不为空?

解决方案

您可以看到,如果任何空这样的:



<$ P $($(this).val()===)
alert(空字段!!);
});

您可以在这里阅读:input selector



获取更具体的答案,如果您只需要这些类型,请将选择器更改为this:

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


How can I check 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!!");
});

这篇关于如何检查表单元素是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆