$(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("
"); html.append("
"); html.append("
"); html.append("
"); html.append(""); html.append("
"); html.append("
"); html.append(""); html.append("
"); html.append("
") html.append("
"); html.append("
"); return html; }; var getRootPath = function(){ //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp var curWwwPath=window.document.location.href; //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp var pathName=window.document.location.pathname; var pos=curWwwPath.indexOf(pathName); //获取主机地址,如: http://localhost:8083 var localhostPaht=curWwwPath.substring(0,pos); //获取带"/"的项目名,如:/uimcardprj var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1); return (localhostPaht+projectName); }