Javascript HTML 文件输入 JS 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2296572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML File input JS events
提问by Adam Kiss
Are there any JavaScript events in type=fileinput? I.E. I would like to add an extra file inputupon selecting file in one of allready created:
type=file输入中是否有任何 JavaScript 事件?IE 我想file input在已经创建的一个文件中选择文件时添加一个额外的:
Diagram:] :
图表:] :
file input 1
file input 2
file input 3
user selects some file in input 1and JS adds new file input
用户在其中选择一些文件input 1,JS 添加新的文件输入
file input 1 - somefile.txt
file input 2
file input 3
*NEW* file input 4
I'm looking for meaningful event, on which i can bind addFileInputmethod.
我正在寻找有意义的事件,我可以在该事件上绑定addFileInput方法。
I also use jQuery 1.4 :]
我也使用 jQuery 1.4 :]
Thank you
谢谢
回答by Ionu? G. Stan
I believe onchangeshould work.
我相信onchange应该工作。
回答by Mathieu
Here is the event logged by Firebug when selecting a file with Firebug:
这是使用 Firebug 选择文件时 Firebug 记录的事件:
- click clientX=885, clientY=207
- blur
- focus
- change
- DOMActivate
- DOMActivate
- mouseout clientX=162, clientY=27
- 单击 clientX=885,clientY=207
- 模糊
- 重点
- 改变
- DOM激活
- DOM激活
- mouseout clientX=162, clientY=27
I guess change, is the one you are looking for:
我想改变,就是你要找的那个:
$ ('#your_form_id input[type=file]').live ('change', function () {
$(this).parent ().append ($('<input type="file" />'));
})
you just have to adapt the selector and the previous code should work
你只需要调整选择器,之前的代码应该可以工作
回答by douwe
I think you mean type=file?
我想你的意思是type=file?
The only meaningful way is use both onclick and onchanged and keep track of the contents to see if it is changed.
唯一有意义的方法是同时使用 onclick 和 onchanged 并跟踪内容以查看它是否已更改。

