关于 jquery.form和jquery.validata冲突的解决方案

简介: 他们两个都一个submitHandler; 好好看看吧 //就是加入这个 $.validator.setDefaults({ submitHandler: function(form){ $.

他们两个都一个submitHandler;

好好看看吧

//就是加入这个
$.validator.setDefaults({
    submitHandler: function(form){
    	$.ajax({
			url: '/index.php?ctrl=feedback&act=index',
			type: 'post',
			dataType: 'text',
			data: $("form").serialize() ,
			success:  function (result) {
				if(result==1111){
						$(".err-box").html('success');
				}else if(result==1002){
					$(".err-box").html('check code error');
				}else{
					$(".err-box").html('error');
				}
				$(".err-box").show();
				$("#submitbutton").attr('src',"<?=DOC_ROOT?>images/sendbtn-b.png");						
			},
			beforeSend: function(){
				$("#submitbutton").attr('src',"<?=DOC_ROOT?>images/loading.gif");
				$("#submitbutton").attr('disabled',true);
			}	
				
		});
		return false;
    }
});

$(function(){
	// ----------------上传 start
	var bar = $('.bar');
    var percent = $('.percent');
    //var showimg = $('#showimg');
    var progress = $(".progress");
    var btn = $(".btn span");
    $("#fileupload").wrap("<form id='myupload' action='/index.php?ctrl=feedback&act=upload' method='post' enctype='multipart/form-data'></form>");
    $("#fileupload").change(function(){
        $("#myupload").ajaxSubmit({
            dataType:  'json',
            beforeSend: function() {
            //    progress.show();
                var percentVal = '0%';
                bar.width(percentVal);
                percent.html(percentVal);
                btn.html("upload loading...");
            },
            uploadProgress: function(event, position, total, percentComplete) {
                var percentVal = percentComplete + '%';
                bar.width(percentVal);
                percent.html(percentVal);
            },
            success: function(data) {
            	btn.html("upload success!");
            	$("#attachments").val(data.path);
            },
            error:function(xhr){
                btn.html("upload failed !");
                bar.width('0')
               // files.html(xhr.responseText);
            }
        });
    });
	// ----------------- end 



	
	$("img#vcodeImg").bind("click",function(){
		// $("img#vcodeImg").attr('src',"<?=DOC_ROOT?>images/loading.gif");
		$("#vcodeImg2").show();
		document.getElementById('vcodeImg').onload=function(){
			$("#vcodeImg2").hide();
		}
		 document.getElementById('vcodeImg').src='/index.php?ctrl=feedback&act=verifyimg&' + Math.random();
		 
	});
	$("#name2").bind("focus",function(){
		//$("img#vcodeImg").attr('src',"<?=DOC_ROOT?>images/loading.gif");
		document.getElementById('vcodeImg').onload=function(){
			$("#vcodeImg2").hide();	
		}
		document.getElementById('vcodeImg').src='/index.php?ctrl=feedback&act=verifyimg&' + Math.random();
		$("#name2").unbind("focus");
		
		$("#vcodeImg2").show();
	});
	$("#feedback_post_form").validate({
		rules: {
			email: {
				required: true,
				email: true
			},
			name:{
				required:true,
				maxlength:20,
				minlength:2
			},
			subject:{
				required:true,
				maxlength:20,
				minlength:2
			},
			description:{
				required:true,
				maxlength:1000,
				minlength:10
			},
			name2:{
				required:true,
				maxlength:4,
				minlength:4
			}
		},
		messages: {
				
				email: {
				/*	required: "input Email address",
					email: "validata email!"*/
				},
				name:{
				}
			}
		/*,
		submitHandler:function() {  
				$.ajax({
					url: '/index.php?ctrl=feedback&act=index',
					type: 'post',
					dataType: 'text',
					data: $("form").serialize() ,
					success:  function (result) {
						if(result==1111){
								$(".err-box").html('success');
						}else if(result==1002){
							$(".err-box").html('check code error');
						}else{
							$(".err-box").html('error');
						}
						$(".err-box").show();
						$("#submitbutton").attr('src',"<?=DOC_ROOT?>images/sendbtn-b.png");						
					},
					beforeSend: function(){
						$("#submitbutton").attr('src',"<?=DOC_ROOT?>images/loading.gif");
						$("#submitbutton").attr('disabled',true);
					}	
						
				});
			}*/
		});

})

  

目录
相关文章
Jquery.Form和jquery.validate 的使用
var form=$('#xxxForm'); var error=$('.alert-danger',form); form.validate({ errorElement:'span', ...
921 0
|
6月前
|
JavaScript 前端开发
百叶窗效果的jQuery幻灯片插件
百叶窗效果的jQuery幻灯片插件
|
6月前
|
JavaScript
jquery无限循环内容滑块插件
jquery无限循环内容滑块插件
|
6月前
|
JavaScript
简单轻量级的jquery图表插件
简单轻量级的jquery图表插件
|
6月前
|
JavaScript
jQuery响应式内容选项卡插件
jQuery响应式内容选项卡插件
|
6月前
|
JavaScript 前端开发
带完成百分比的jQuery表单插件
带完成百分比的jQuery表单插件
|
6月前
|
JavaScript 内存技术
支持多种动画特效的响应式jQuery幻灯片插件
支持多种动画特效的响应式jQuery幻灯片插件
|
8月前
jQuery+Slick插件实现游戏人物轮播展示切换源码
jQuery+Slick插件实现游戏人物轮播展示切换源码
111 14
|
9月前
|
JavaScript 前端开发
jQuery和CSS3滑动展开菜单按钮插件
这是一款jQuery和CSS3滑动展开菜单按钮插件。该滑动展开菜单按钮在用户点击主菜单按钮之后,子菜单以滑动的方式依次展开
129 21
|
9月前
|
JavaScript
jquery图片和pdf文件预览插件
EZView.js是一款jquery图片和pdf文件预览插件。EZView.js可以为图片和pdf格式文件生成在线预览效果。支持的文件格式有pdf、jpg、 png、jpeg、gif。
269 16