教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 jquery 必填项判断表单是否为空的方法

jquery 必填项判断表单是否为空的方法

发布时间:2013-04-30   编辑:jiaochengji.com
jquery 表单验证,检测表单是否为空
jquery 表单验证,检测表单是否为空 html页面
复制代码 代码如下:

<form onsubmit="if(confirm('确定好你所填写的正确,不然会发错!')) {return checkForm();}else{return false;}" >
<table >
<tr>
<td>选择发送人<font class="red">*</font></td>
<td>
<input type="text" name="sendto_type[]" id="sendto_type1" value="1" >按城市发送

</td>
</tr>

<tr>
<td>选择发送人2<font class="red">*</font></td>
<td>
<input type="text" name="sendto_type[]" id="sendto_type1" value="1" >按城市发送
</td>
</tr>
</table>
</form>

js代码
复制代码 代码如下:

<script>
function checkForm() {
pass = true;
$("td:contains('*')").next().find("input").each(function(){
if(this.value == '') {
text = $(this).parent().prev().text();
alert(text+"是必填项");
this.focus();
pass = false;
return false;//跳出each
}
});
return pass;
}
</script>

您可能感兴趣的文章:
jquery 必填项判断表单是否为空的方法
jquery 判断 radio checkbox 是否选中的几种方法
js 检验(input、radio、checkbox、textarea)必填项的代码
Jquery 获取表单text,areatext,radio,checkbox,select值的代码
jquery获取元素值的方法(常见的表单元素)
JQuery 常用操作代码
jquery 表单取值常用代码
jQuery select操作控制方法小结
php设置文本框不能为空
PHP判断变量是否已存在

[关闭]
~ ~