点击打开文件上传对话框 [英] open file upload dialog on click

查看:110
本文介绍了点击打开文件上传对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须打开文件上传对话框,通过点击其他按钮,即我隐藏文件上传控制(知名度:隐藏),并点击其他一些按钮,我想打开该对话框。
下面是我有的代码:

 < input type =filestyle =visibility:隐; /> 

以下是javascript:

<$ p $ ();
$('input [type = file]')。click();
});

在Firefox 4和IE8中工作正常,但是在chrome12中它不工作,即对话框不是被打开。任何想法为什么?

解决方案

现在测试问题和情况中给出的简单代码已经改变:


  • IE9:作品

  • Chrome23:作品

  • Firefox15:作品
  • >


只有一个catch-on IE,.click()是一个阻塞操作,而在其他浏览器上则不是。 b $ b

I have to open file upload dialog by clicking some other button i.e i am hiding file upload control(visibility:hidden) and on clicking of some other button i want to open that dialog. Below is the code which i am having:

<input type="file" style="visibility: hidden;" />

Below is the javascript:

$('#button').click(function() {
    $('input[type=file]').click();
});

It is working fine in Firefox 4 and IE8 but in chrome12 it is not working i.e the dialog is not being opened. Any idea why?

解决方案

Tested today the simple code given in the question and the situation has changed:

  • IE9: works
  • Chrome23: works
  • Firefox15: works

There is just one catch - on IE the .click() is a blocking operation while on other browsers it is not.

这篇关于点击打开文件上传对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆