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

他们两个都一个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);
					}	
						
				});
			}*/
		});

})

  

上一篇:小视频源码是如何发展到今天的,看完你就明白了


下一篇:用C#快速往Excel写数据