Home  >  Article  >  Web Front-end  >  JavaScript implementation to limit upload file size_javascript skills

JavaScript implementation to limit upload file size_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:15:361311browse

Foreword:

In projects, functions such as uploading files and photos are often used, and the size of the uploaded files needs to be limited. Many plug-ins use background request verification, and there are relatively few front-end JS verifications. This article introduces a front-end JS method to conveniently determine the size of uploaded files.

The code is very simple. The key is how to use JS to get the file and then get the file size, and then judge the interception. Due to various historical reasons and IE's ActiveX control factors, the method of obtaining files may be different from other browsers, so you only need to make a little judgment.

JS code:

Copy code The code is as follows:



HTML code

Copy code The code is as follows:


A simple, light and fast method to use JS code to determine the file size is OK. As for the ActiveXObject object, if you are interested, you can delve into it. It can return different objects according to different input parameters. Usually, the function of this object and effects are also very useful and powerful.

That’s it for this article. Isn’t it a very simple and practical code? I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn