Home  >  Article  >  Web Front-end  >  JS simple implementation of file upload example code (no plug-in required)_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 17:14:581345browse

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

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