<span class=\"up-btn\" id=\"selectFile\">请选择文件</span>
<input type=\"file\" name=\"fileupload\" style=\"FILTER: alpha(opacity=0); moz-opacity: 0; opacity: 0;\" />
// 点击#selectFile触发input:file的click事件
jQuery(\'#selectFile\').live(\'click\',function(){
var ie = !-[1,];
if(ie){
jQuery(\'input:file\').trigger(\'click\').trigger(\'change\');
}else{
jQuery(\'input:file\').trigger(\'click\');
}
});
选中文件要触发的事件
jQuery(\'input:file\').change(function(){
//dosomthing
});
注意事项:
1、在chrome浏览器下,为了数据安全,隐藏的input:file不能trigger “click” 事件。 所以要设置input:file的透明度达到隐藏的效果。
2、在ie6,7下input file文件不支持onchange事件,所以在此浏览器下我还是用<input type=\"file\" value=\"\" />
本文地址:https://www.stayed.cn/item/12993
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我