如何使用脚本打开文件对话框或浏览文件窗口? [英] How to open a File Dialog or Browse Files Window using Scripts?

查看:181
本文介绍了如何使用脚本打开文件对话框或浏览文件窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢展示图片或html的任何元素,并初始化它的高度。当我在像这样的图像背后使用HTML文件类型的输入:

 < img src =image.png > 
< input type =filename =imageid =booksimagestyle =opacity:0>

所以输入元素消失了,当我点击图像文件打开对话框打开,但它的作用高度一个正常的输入元素。当我为输入元素设置一个100px的高度时,它的功效不会超过。当我看到html的问题时,我决定使用Javascript或Jquery来解决问题,我搜索了一些类似的问题,如:





但解决方案是为特殊浏览器和Firefox的doesn不支持它。
是否有任何其他方式通过单击图像打开文件浏览器对话框?!

解决方案

  $('img')。click(function(){
$('input [type =file]')。click();
});


I like to show an image or any elements of html and initialize a height to it. When i used a file type of input in html behind of an image like this :

<img src="image.png">
<input type="file" name="image" id="booksimage" style="opacity: 0">

So input element disappeared and when I clicked on image File Open Dialog opened but it works in a height of a normal input element. when I set a height of 100px to input element it dose not work more than.

When I see that problem of html, I decided to Use Javascript or Jquery to solve problem, I searched an find some similar issues like :

How to open a file / browse dialog using javascript?

but solution is for special browsers and firefox doesn't support it. Is there any other way for open File Browser Dialog by clicking on an image?!

解决方案

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

这篇关于如何使用脚本打开文件对话框或浏览文件窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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