zl程序教程

您现在的位置是:首页 >  前端

当前栏目

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

jQuery方法 判断 是否 表单 为空 必填
2023-06-13 09:14:02 时间
html页面
复制代码代码如下:

<formonsubmit="if(confirm("确定好你所填写的正确,不然会发错!")){returncheckForm();}else{returnfalse;}">
<table>
<tr>
<td>选择发送人<fontclass="red">*</font></td>
<td>
<inputtype="text"name="sendto_type[]"id="sendto_type1"value="1">按城市发送

</td>
</tr>

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

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

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