$(function(){ $(".web-upload").each(function(index,dom){ $(dom).webuiUpload(); }); }); (function(){ $.fn.webuiUpload = function(callback){ if($("#newtouch_uploadDiv").length == 0){ var html = uploadHTML().toString(); $("body").append(html); $("#newtouch_uploadDiv").css("display","none"); $('#newtouch_uploadForm').ajaxForm( { beforeSubmit : function(formData, jqForm, options) { if (!$("#newtouch_dataFile").val()) { alert("请选择上传的文件"); return false; } }, success : function(data) { var message = eval("(" + data + ")"); if (typeof (message.error) != "undefined") { alert(message.error); return; } else { $("#newtouch_uploadDiv").dialog('close'); if(callback){ if(typeof(failCallback)=="function"){ failCallback(data); } if(typeof(failCallback)=="string"){ eval(failCallback); } } alert("上传成功!"); } } }); } $("#"+$(this).attr("id")).bind("click",function(){ $("#newtouch_uploadDiv").dialog({width:350}); }); }; })(jQuery); var uploadHTML = function(){ var html = new StringBuffer(); html.append("