Home > Web Front-end > JS Tutorial > body text

JS simple implementation of file upload example code (no plug-in required)_javascript skills

WBOY
Release: 2016-05-16 17:14:58
Original
1352 people have browsed it

Copy code The code is as follows:

Please select the file


// Click #selectFile to trigger the click event of input:file
Copy code The code is as follows:

jQuery('#selectFile').live('click',function(){
var ie = !-[1,];
if( ie){
jQuery('input:file').trigger('click').trigger('change');
}else{
jQuery('input:file').trigger(' click');
}

});

The event to be triggered by selecting the file
Copy code The code is as follows:

jQuery('input:file').change(function(){
//dosomthing
});

Note:

1. Under the Chrome browser, for data security, the hidden input: file cannot trigger the "click" event. So you need to set the transparency of input: file to achieve the hidden effect.

2. The input file under IE6 and 7 does not support the onchange event, so I still use

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!