源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-12-25 18:29 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jquery 必填项判断表单是否为空的方法
html页面
[u]复制代码[/u] 代码如下:
<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代码
[u]复制代码[/u] 代码如下:
<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>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部