Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use js plug-in imgFileupload.js for batch upload of pictures

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

图片批量上传js插件imgFileupload.js怎么用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

插件Demo展示

插件功能介绍

1、批量选择图片,限制图片的类型 (通过限制file的accept),只能选择图片

默认:accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"

2、可以自定义限制选择图片的数量,默认5张

3、可以自定义限制图片的最大宽度和最大高度,默认都是10000px

4、可以自定义限制图片的单文件大小,默认是4MB

5、使用简单引用css和js ,并且在页面加上标签 即可使用

代码Demo

轻量级图片批量上传JS插件imgFileupload var imgFile; $(function () { imgFile = new ImgUploadeFiles('.review_img', function (e) { this.init({ MAX: 6, //Limit the number of images FileSize: 1024 * 1024 * 4,//单文件限制4MB(注意:单位KB) callback: function (arr) { console.log(arr) } }); }); }); function submit() { var formData = new FormData(); $(".review_img li").each(function (i, item) { formData.append("file", $(item).data("file")); }); formData.append("parameter1", $("#parameter1").val()); formData.append("parameter2", $("#parameter2").val()); formData.append("parameter3", $("#parameter3").val()); formData.append("parameter4", $("#parameter4").val()); formData.append("parameter5", $("#parameter5").val()); $.ajax({ url: "/Index/Write", type: "POST", dataType: "json", data: formData, async: true, cache: false, ontentType: false, processData: false, beforeSend: function () { }, success: function (data) { alert("ok"); }, error: function () { alert("Sorry"); } }); }

多次选择文件的情况,File元素中的filedata内容始终是当前选择的文件,上一次选择的文件则被替换掉

并且由于浏览器安全问题,JavaScript无法操作File文件上传中的filedata中的文件,无法把多次选择的文件赋值到File元素的filedata中,由此造成无法直接用form表单直接提交File元素中的文件

所以这里我们使用formData来提交文件和参数,没有使用form表单提交

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report