1、Jquery form表单ajax提交 2、jquery.filter校验多个相同类型的文本框是否输入数据有重复

JSP引用该JS

<script type="text/javascript" src="http://malsup.github.com/jquery.form.js"></script>


表单保存按钮 οnclick=save();

function save(){
	var ipts = $('.resblockName'), repeat = '';
    $(".resblockName").each(function () {
        if (ipts.filter('[value="' + this.value + '"]').size()>1) {
            repeat = this.value;
            return false;
        }
    });
    if (repeat !== ''){ 
    	alert('有重复名称,为:' + repeat + '!');
    	return false;
    }
	if(confirm("上传压缩包文件大,耗时长,需要您耐心等待,确定要上传吗?")){
		//上传按钮置灰,新增按钮置灰
		//$("#bsubmit").attr("disabled" , true).html("<i class=\"icon-spinner icon-spin\"></i> 正在提交中...").attr("onclick","");
		$("#bsubmit").attr("disabled" , true).attr("onclick","");
		$("#newBtn").attr("disabled" , true).attr("onclick","");
		$(".uploadForm").each(function(index){//form-index
			//判断是否有值
			var resblockId=$(this).find(".resblockId").val();
			var fileName=$(this).find(".tp").val();
			if(fileName=='' || resblockId==''){
				$(".upload-msg-span").eq(index).attr("style","color:red;").html("<i class=\"fa fa-times\"></i>名称及文件必选。");
				return true ;
			}
			$(this).ajaxSubmit({  
				url:"<%=basePath%>picture/saveResblock720.do",
				iframe: true,
		        enctype:'multipart/form-data',
		        success:function(data, statusText) {
		        	var resultMsg="";
		           	if(data!=null){
		           		resultMsg=data.resultMsg;
		           		if(data.resultStatus==200){
		           			resultMsg="<i class=\"icon-ok\"></i>"+resultMsg;	
		           			$(".upload-msg-span").eq(index).attr("style","color:blue;").html(resultMsg);
		           		}else{
		           			resultMsg="<i class=\"fa fa-times\"></i>"+resultMsg;
		           			$(".upload-msg-span").eq(index).html(resultMsg);
		           		}
		           	}
		           	
		        },error: function(arg1, arg2, ex) {
		        	var resultMsg="<i class=\"fa fa-times\"></i>上传异常,请重试。";
		        	$(".upload-msg-span").eq(index).html(resultMsg);
		        },
		        dataType: 'json'
		   });
		});
		// 文件上传结束后的 按钮修改
		//$("#bsubmit").html("<i class=\"icon-ok\"></i>上传结束");
	}
}

$(document).ready(function() {   
    var options = {   
        target:        '#mydiv',   // 需要刷新的区域  
        //beforeSubmit:  showRequest,  // 提交前调用的方法  
        //success:       showResponse  // 返回后笤俑的方法  
   
        // other available options:   
        //url:       url         // 提交的URL, 默认使用FORM  ACTION   
        //type:      type        // 'get' or 'post', override for form's 'method' attribute   
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type)   
        //clearForm: true        // 是否清空form  
        //resetForm: true        // 是否重置form  
   
        // $.ajax options can be used here too, for example:   
        //timeout:   3000   
    };   
   
    // 绑定FORM提交事件  
    $('#myForm').submit(function() {   
        $(this).ajaxSubmit(options);   
   
        // !!! Important !!!   
        // always return false to prevent standard browser submit and page navigation   
        return false;   
    });   
});   

转自: http://www.cnblogs.com/yqskj/archive/2013/06/05/3119479.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值