您的位置:首页 > Web前端 > JQuery

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

2008-09-14 00:00 447 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: