$(function () { var div = $("#button_warp"); if (div.length) { loadjs("/user/jquery.validate.js", function () { loadjs("/user/jquery.form.js", function () { var html = [ '
' ].join(''); div.append(html); $.validator.setdefaults({ submithandler: function () { if (!checkfile("#businesslicense") || $("#commentform").find("label.error_,label.error").filter(":visible").length > 0) { return false; } showbgproc(true, "正在注册,请稍候..."); $("#oid").val(obj_id); $("#commentform").ajaxsubmit({ type: "post", url: "/ajax.ashx?action=saveagentapply&time=" + (new date()).gettime(), success: function (msg) { if (msg) { $a(msg); } else { $a("提交成功,感谢您的参与,我们将会尽快联系您!"); $("#reset").click(); } showbgproc(false); } }); return false; } }); function checkfile(src) { src = $(src); var filename = src.val(); var fileextension = filename.substring(filename.lastindexof('.') + 1); var types = 'gif,jpg,jpeg,png,bmp,doc,docx,xls,xlsx,ppt'; var label = src.siblings("label.error_").hide(); if (label.length == 0) { src.after(''); label = src.next("label.error_"); var l = 10, t = 3; } label.css("position", "absolute").css("top", src.offset().top + t).css("left", src.offset().left + src.width() + l); if (!fileextension || (',' + types + ',').indexof(fileextension) == -1) { label.html("请上传" + types + "类型的文件!").show().siblings(".error").hide(); src.val(""); return false; } else { label.hide(); } return true; } $("#commentform").validate({ rules: { quote: { required: true }, delivery: { required: true }, paymentmethod: { required: true }, quality: { required: true }, qualityassurancetime: { required: true }, vcode: { required: true, maxlength: 4, minlength: 4 } } }); $("#vcode").one("click", function () { $(this).next().find("img").click(); }) $("#businesslicense").bind("change", function () { checkfile(this); }) }) }) } })