jsp+ajax实现无刷新上传文件的方法(3)

(function(){ $.fn.extend({ ajax_edit:function(str,oldValue){ return this.each(function(){ $this = $(this); var id; var nameId = $this.attr("class").split(" ")[1]; var idName = $this.parents("tr.package_list").find("td:first-child :input[type=checkbox]").attr("class").split(" ")[1]; id = $this.siblings("."+idName+"_td").find("input").val(); if(nameId == "categoryName" && str == "editaddress.jsp"){ $this.load("categorylist.jsp",{'oldValue':oldValue,'urlid':id}); }else{ $this.html("<form><input type='hidden' value='"+id+"' /><input type='hidden' value='"+nameId+"' /><input type='text' value='"+oldValue+"'/></form>"); $this.find(":input:last").focus(); } }) }, ajax_edit_img:function(str,oldValue){ //处理图片上传AJAX 关键的一步form表格里的 target='hidden_frame'提交到ID为hidden_frame的iframe里面 return this.each(function(){ var $this = $(this); var nameId = $this.attr("class").split(" ")[1]; var idName = $this.parents("tr.package_list").find("td:first-child :input[type=checkbox]").attr("class").split(" ")[1]; var id = $this.siblings("."+idName+"_td").find("input").val(); var $imgForm = $("<form action='editaddress.jsp?action=edit&target=imageurl' method='post' enctype='multipart/form-data' target='hidden_frame'><input type='hidden' value='"+id+"' /><input type='file' /><input type='button' value='取消' /><input type='button' value='上传' /></form>"); $this.html($imgForm); $this.find(":input:last").focus(); $imgForm.find(":input[type=file]").bind("change",function(){ $(this).fileTypeJudge("photo"); }) $imgForm.find(":input.ok").bind("click",function(){ var $button = $(this); if($imgForm.find(":input[type=file]").val()==''){ alert("请上传图片!"); return false; } $button.attr("disabled",true); $("#selectaddressForm_img").submit(); }) $imgForm.find(":input.cancel").bind("click",function(){ $(this).parents(".edit_img").html(oldValue); }); }) }, ajax_handle:function(str,oldValue){ return this.each(function(){ var $this = $(this); setTimeout(function(){ if(!$("div").hasClass("datepick-control") || !$("div .datepick-control").is(":visible")){ if(oldValue != $this.val() && $this.val() !="" ){ $.post( str,$("#selectaddressForm").serialize(), function(data){ $this.parents(".edit").text(data.trim()).css("color","red"); } ) }else{ $this.parents(".edit").text(oldValue); } } },1000); }) } }) })(jQuery)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wfywsz.html