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>

时间: 2024-09-19 10:08:26

jquery 必填项判断表单是否为空的方法_jquery的相关文章

jQuery基本选择器(实例及表单域value的获取方法)_jquery

jQuery基本选择器包括 CSS选择器.层级选择器和.表单域选择器. 1.CSS选择器 (1)标签选择器 $("div")  $("p")  $("table") 等一系列 HTML 标签 (2)ID选择器 <input id="user" type="text"> 获取该标记的值:$("#user").val(); (3)类选择器 <input type="

jQuery动态添加及删除表单上传元素的方法(附demo源码下载)_jquery

本文实例讲述了jQuery动态添加及删除表单上传元素的方法.分享给大家供大家参考,具体如下: 运行效果截图如下: 点击此处查看在线演示效果. 具体代码如下: <html> <head> <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(d

jQuery根据表单name获取值的方法_jquery

本文实例讲述了jQuery根据表单name获取值的方法.分享给大家供大家参考,具体如下: 根据name取值: $("input[name='mobile']").val() 根据id取值: $("#mobile_reg_form").html() 根据name取值遍历: $("input[name='mobile']").each( function(){ alert($(this).val()); } ) 取出form中的input: <

Jquery表单验证插件formValidator使用方法_jquery

使用步骤: 1.首先在项目中添加必备js与css   2.代码中添加引用(必备引用) <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <!--jquery必须库--> <script src="formValidator1/formValidator-4.0.1.min.js" type="te

使用jquery提交form表单并自定义action的方法_jquery

$(function () { $("#btn").click(function () { var usercode = $("#UserCode").val(); var verifycode = $("#Verifycode").val(); if ($.trim(usercode) == "" || $.trim(verifycode) == "") { alert(" 您的[客户号]或者[

jquery将一个表单序列化为一个对象的方法_jquery

复制代码 代码如下: var aa=function(form){ var o={}; $.each(form.serializeArray(),function(index){ if(o[this['name']]){ o[this['name']] = o[this['name']]+","+this['value']; }else{ o[this['name']] = this['value']; } }); return o; }

jquery判断input值不为空的方法_jquery

<input type="text" class="searchbox" /> <script type='text/javascript'> $(document).ready(function(){ //enter回车键激活搜索 $('.searchbox').bind('keypress', function(event) { if (event.keyCode == "13") { search_news(); }

织梦dedecms自定义表单设置必填项的教程

方法一:通过修改程序源文件实现 1.在plus文件夹下找到diy.php文件,对其进行编辑,在第40行左右找到代码: $dede_fields = empty($dede_fields) ? '' : trim($dede_fields); 2.在这行代码下面,添加以下代码后保存文件: //增加必填字段判断  if($required!=''){  if(preg_match('/,/', $required)){  $requireds = explode(',',$required);  f

如何设置dedecms自定义表单必填项?

用dedecms自定义表单可以制作一个简单的预约系统,有些相关信息需要设置为必填项,比如联系方式,没有留下真实的电话或其他信息,以后要怎么联系到你的客户.那我们要如何设置织梦cms自定义表单必填项呢?随ytkah一起试试吧 一.先用一段php代码来判断验证码为必选项.找到文件plus/diy.php文件中的第40行左右加上以下代码: //增加必填字段判断 if($required!=''){if(preg_match('/,/', $required)){$requireds = explode