如何检测输入类型=文件“更改”对于同一个文件? [英] How to detect input type=file "change" for the same file?

查看:103
本文介绍了如何检测输入类型=文件“更改”对于同一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户选择文件时触发事件。如果用户每次更改文件,都可以使用 .change 事件。

I want to fire an event when the user select a file. Doing so with .change event it works if the user changes the file every time.

但是我要启动如果用户再次选择相同的文件,则该事件。

But I want to fire the event if the user select the same file again.


  1. 用户选择文件 A.jpg (事件触发)

  2. 用户选择文件 B.jpg (事件触发)

  3. 用户选择文件 B.jpg (事件不触发,我要它启动)

  1. User select file A.jpg (event fires)
  2. User select file B.jpg (event fires)
  3. User select file B.jpg (event doesn't fire, I want it to fire)

我该怎么做?

推荐答案

你可以欺骗它。删除文件元素并将其添加到更改事件的相同位置。它将擦除文件路径,使其每次都可以更改。

You can trick it. Remove the file element and add it in the same place on change event. It will erase the file path making it changeable every time.

jsFiddle上的示例

Example on jsFiddle.

或者你可以简单地使用 .attr(value ),请参阅 jsFiddle上的此示例

Or you can simply use .attr("value", ""), see this example on jsFiddle.

这篇关于如何检测输入类型=文件“更改”对于同一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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