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 upload multiple pictures in H5

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

Share

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

This article will explain in detail how to upload multiple pictures on H5. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

This article mainly introduces the function of uploading multiple pictures based on HTML5 and the function of uploading multiple pictures on the basis of uploading a single picture. Interested friends can refer to it.

The picture was also written before uploading, but it was uploaded by a single sheet. Recently, there is a business requirement that requires multiple uploads, so I rewrote it.

HTML structure:

Please select an image file:

By the way, the main logic of this upload:

Use the input tag and select type=file, and remember to bring multiple, otherwise you will have to select the picture

Bind the change time of input

The key point is how to deal with this change event, use H5's new FileReader interface to read the file and encode it into base64, and then interact with the back-end students.

JS Code:

_ window.onload = function () {var input = document.getElementById ("file_input"); var result,p; if (typeof FileReader==='undefined') {result [XSS _ clean] = "Sorry, your browser does not support FileReader"; input.setAttribute ('disabled','disabled');} else {input.addEventListener (' change',readFile,false) }

/ / handler function readFile () {for (var iTuno

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