来自JavaScript *的文件对话框,不带*< input> [英] File dialog from JavaScript *without* <input>
问题描述
我正在向现有页面添加文件导入功能。
I am adding file import functionality to an existing page.
我想使用javascript并且不修改页面即可。没有添加input type =file标签,每个人似乎在谈论。
I want to do this using javascript and without modifying the page, ie. without adding the "input type="file" " tag, everyone seems to be talking about.
我已经添加了按钮,现在我想要事件显示文件对话框,用户浏览文件和javascript,将文件提交到服务器进行验证。
I have added the button, now I want the event to show the file dialog, user to browse for file and javascript to submit file to server for validation.
我该怎么做?
Btw,主要优先级是打开文件对话框,所以不需要用户或提交部分,如果你不知道的话。
How do I do that? Btw, main priority is opening file dialog, so no need for user or submitting part, if you don't know it.
Thx
推荐答案
嗯,如果我明白你想要的是什么,是这样的...
Well, if I understand correct what you want, is some like this...
<input type="button" value="Add File" onclick="document.getElementById('file').click()" />
<input type="file" id="file" style="display:none" />
冒犯文件
对象并调用文件与另一个对象的对话。对吧?
Hidding the file
object and calling the file dialog with another object. Right ?
编辑:只有Javascript
onclick =var f = document.createElement('input'); f.style.display ='none'; f.type ='file'; f.name ='file'; document.getElementById('yourformhere')。appendChild (f); f.click();
将它放在你的对象中,使用 id $您的
表单
代替 yourformhere
!!
Put this in your object with the id
of your form
in place of yourformhere
!!
这篇关于来自JavaScript *的文件对话框,不带*< input>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!