按钮显示选择要上传的文件对话框

按钮显示选择要上传的文件对话框

本文介绍了按钮显示选择要上传的文件对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代替使用 input type =file html标记,是否可以显示选择要上传的文件 input type =button?c $ c>对话框。然后,当从中选择一个文件时,选择要上传的文件对话框,文件路径将被插入到常规html input type =text 标记?

Instead of using an input type="file" html tag, is it possible to bring up a choose a file to upload dialog box by clicking a input type="button"? Then when a file is selected from the choose a file to upload dialog box, the file path gets inserted into a regular html input type="text" tag?

我好像gmail做了类似的事情,但没有按钮和文本输入,它们只是有一个链接添加文件或类似的东西。点击该链接时,它会显示选择要通过mail.google.com 对话框上传的文件。当文件被点击时,文件名会显示在屏幕上。

I've seem that gmail does something similar but not with buttons and text inputs, they simply have a link add file or something like that. When that link is clicked, it shows the select file(s) to upload by mail.google.com dialog box. When a file is clicked, the file name is shown on the screen.

他们是怎么做的?

How are they doing that?

推荐答案

我认为大多数浏览器为了安全目的而锁定了这个。按钮和文本框可以通过JavaScript进行操作。文件输入框不能,并且有很好的理由;想象一下,如果一个javascript可以打开一个对话框,将路径设置为系统中的敏感文件,然后模拟按钮点击下载文件!

I think most browsers have this locked down for security purposes. Buttons and text boxes can be manipulated via JavaScript. File input boxes cannot, and for good reason; imagine if a javascript could open a dialog, set the path to a sensitive file on your system, then simulate the button click to download the file!

顺便说一下,如果你正在寻找样式,或许这会起作用:

By the way, if you are looking to style it, perhaps this would work: http://www.quirksmode.org/dom/inputfile.html

这篇关于按钮显示选择要上传的文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 16:37