This afternoon to help colleagues changed such a bug:
when uploading multiple images on a single page, the value of input cannot be a problem, resulting in the same effect as the first picture after each selection:
Baidu took the next train of thought: first to take input, and then put into a temporary form inside empty, and finally delete the form.
The code is as follows:
The first is to generate the binding code for the picture selection and Display section:
var img_tmp = ' <tr><td><input type= ' text "name=" code "value=" "style=" width:90%; Display:none; " ><input type= "text" name= "title[" "style=" width:90%; "/></td><td><input type=" text "Name=" Sort[] "style=" width:90%; "/></td><td><input type=" text "Name=" num[] "style=" width:90%; " /></td> ' + ' <td><div class=" File_box "> ' + ' <input Type= "button" class= "btn" value= "select Picture"/> ' + ' <input type= "file" name = "Filelogo" class= "file" id= "style=" width:80%; "onchange=" UploadImages (This) "/>" + ' </div></td> ' + ' <td><a clAss= "del" href= "javascript:void (0)" > Delete </a></td></tr> ";
In the method onchange= "UploadImages (This)" Here, we pass in the click Input to commit:
Multi-image upload function uploadimages (FileInput) {//var Isno = Filechange ($ (FileInput)); if (Isno = = undefined) {var options = {type: "POST", url: '). /handler/ashxuploadfile.ashx?type=images ', Success:function (msg) {if (msg = = "Error") {clearimages ($ (FileInput)); Showerrortip ("Upload failed"); } else {if (msg! = "ErrorType") {clearimages ($ (FileInput)); $ (FileInput). Parent (). Prev ("img"). attr ("src", Strpic + msg); Clearimages ($ (FileInput)); $ (FileInput). attr ("Style", ""); }}}, Error:function (msg) {clearimages ($ (FileInput)); $ (FileInput). attr ("Style", ""); Showerrortip ("parameter exception! "); } }; Pass the options to Ajaxform $ (' form '). Ajaxsubmit (options); //} }
The problem was caused by ignoring the cleanup of input, adding the Clearimages function:
function Clearimages (selector) { var fi; var sourceparent; if (selector) { fi = $ (selector); Sourceparent = Fi.parent (); } else { return; } $ ("<form id= ' tempform ' ></form>"). AppendTo (document.body); var tempform = $ ("#tempForm"); Tempform.append (FI); Tempform.get (0). Reset (); Sourceparent.append (FI); Tempform.remove (); }
in this way, the input is emptied using the temporary form.
Process the upload of images with form+input[type= "file" on the same page cannot empty the problem