< input type ='file'/>>替换onchange事件 [英] alternate to onchange event in <input type='file' />

查看:205
本文介绍了< input type ='file'/>>替换onchange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来真的很简单,但是搞不清楚。我一直在元素上使用onchange事件,它运作良好。一旦用户浏览并选择一个文件,我得到的路径,并上传它使用我的自定义js函数。

问题是,这是行不通的,如果用户选择在同一个文件连续两次,onchange不会触发(这是有道理的,因为没有任何改变),但在我的情况下,我也很重要的捕获该事件,获取路径和上传。

编辑



(与清除< input type ='file'/>使用jQuery ,不确定是否应该将其解析为重复)

解决方法

您可以删除输入并使用javascript创建一个相同的输入 - 新的输入为空。



到现在为止,评论是不相关的)

Seems really a simple thing but can't figure it out. I've been using the onchange event on element and it works well. Once the user browses and selects a file, I get the path and upload it using a my custom js function.

The problem is this doesn't work if a user selects the same file twice in a row, the onchange doesn't fire (which makes sense since nothing changed) but in my case it's important for me to capture that event too, get the path and upload.

Edit

(Similar to Clearing <input type='file' /> using jQuery, not sure if I should resolve this as duplicate)

解决方案

You can just remove the input and create an identical one with javascript - the new one will be empty.

(edited answer to be straight to the point, comments are irrelevant now)

这篇关于&lt; input type ='file'/>&gt;替换onchange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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