Multiple upload files use js to verify the file format and size (recommended ).
Html section:
<Dsp: form action = "$ {originatingRequest. requestURI} "method =" post "enctype =" multipart/form-data "> <dsp: input type =" file "bean =" ReturngoodsFormHandler. uploadedFile1 "id =" uploadedFile1 "value =" "onchange =" checkfile ('uploadedfile1'); "/> <dsp: input type =" file "bean =" ReturngoodsFormHandler. uploadedFile2 "id =" uploadedFile2 "value =" "onchange =" checkfile ('uploadedfile2'); "/> <a class =" btn_sprite btn_font14_red "href =" javascript :; "rel =" external nofollow "> <span> submit an application </span> </a> <dsp: input type =" submit "style =" display: none; "bean =" ReturngoodsFormHandler. submitReturngoods "id =" submitReturngoods "value =" Add "/> </dsp: form>
Note: The Upload file must have an id, and an id name should be added to the onchage event;
Js section:
// Detaches verification settings and error messages, facilitating the final submission of var flag = true; var errorinfo = ""; // verifies the file format function checkfile (filenames) {filename = document. getElementByIdx_x_x (filenames ). value; var re = /(. [.] bmp) $ | (. [.] gif) $ | (. [.] jpg) $ | (. [.] png) $ | (. [.] jpeg) $/I; if (! Re. test (filename) {errorinfo = "only bmp, gif, jpg, png, and jpeg files are supported. upload files again"; alert (errorinfo); flag = false; return false;} // verify the file size if (document. getElementByIdx_x_x (filenames ). size> 8000) {errorinfo = "the file must be smaller than kb, and the image size is too large:" + document. getelementbyidx_x_x_x_x (filenames ). size; alert (errorinfo); return false ;}} jQuery ('. btn_font14_red '). click (function () {if (flag = true) {$ ("# submitReturngoods "). click () ;}else {alert (errorinfo); return false ;}});
Note:The advantage of doing so is: first, if an error occurs during file upload, the user is notified immediately and the user can modify it;
Second, if the user has completed the last filling, even though there is a prompt statement, but the user forgot what it is, when clicking submit, the user can still be prompted for the cause of the problem. At the same time, you can save page efficiency by placing the error message and setting value on the outermost side without further verification.
(Document. getElementByIdx_x_x (filenames) does not know why multiple _ x files are always used for posting, but they cannot be removed. Remember to remove them when copying files)
The above method for verifying the format and size of multiple uploaded files using js (recommended) is all the content shared by Alibaba Cloud xiaobian. I hope to give you a reference, we also hope that you can support the customer's home.