Home Web Front-end JS Tutorial Code to determine whether multiple input type=files have selected files_jquery

Code to determine whether multiple input type=files have selected files_jquery

May 16, 2016 pm 05:53 PM
file

There are multiple <input type="file" name="uploadfile" contentEditable="false" style="width:80%"> in the form.
When submitting the form, you need to determine that at least one of the inputs has been selected. Good document.

Copy code The code is as follows:

<input type="file" name="uploadfile " contentEditable="false" style="width:80%"><br>
<input type="file" name="uploadfile" contentEditable="false" style="width:80%"&gt ;<br>
<input type="file" name="uploadfile" contentEditable="false" style="width:80%"><br>
<input type="file " name="uploadfile" contentEditable="false" style="width:80%"><br>
<input type="file" name="uploadfile" contentEditable="false" style="width :80%">

Use jQuery to judge:
Copy code The code is as follows:

var fileFlag = false;
$("input[name='uploadfile']").each(function(){
if($(this).val()! ="") {
fileflag = true;
return false;
}
});
if(fileFlag) {
alert("The file has been selected") ;
}

As long as fileFlag is true, you can exit the each loop and there is no need to judge the remaining input.
Use return false in each to exit the loop, use return true to end the current loop and proceed to the next loop.
Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hongmeng native application random poetry Hongmeng native application random poetry Feb 19, 2024 pm 01:36 PM

Hongmeng native application random poetry

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use java's File.length() function to get the size of the file

How to convert php blob to file How to convert php blob to file Mar 16, 2023 am 10:47 AM

How to convert php blob to file

Rename files using java's File.renameTo() function Rename files using java's File.renameTo() function Jul 25, 2023 pm 03:45 PM

Rename files using java's File.renameTo() function

Use java's File.getParentFile() function to get the parent directory of the file Use java's File.getParentFile() function to get the parent directory of the file Jul 27, 2023 am 11:45 AM

Use java's File.getParentFile() function to get the parent directory of the file

Use java's File.getParent() function to get the parent path of the file Use java's File.getParent() function to get the parent path of the file Jul 24, 2023 pm 01:40 PM

Use java's File.getParent() function to get the parent path of the file

How to delete a file or directory using File.delete() method in Java? How to delete a file or directory using File.delete() method in Java? Nov 18, 2023 am 08:02 AM

How to delete a file or directory using File.delete() method in Java?

WebView File Domain Origin Policy Bypass Vulnerability Example Analysis WebView File Domain Origin Policy Bypass Vulnerability Example Analysis May 15, 2023 am 08:22 AM

WebView File Domain Origin Policy Bypass Vulnerability Example Analysis

See all articles