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

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

问题描述

我想在用户选择文件时触发事件。使用 .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.

但我想


  1. 用户选择文件 A.jpg

  2. >用户选择文件 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)

我该如何做?

推荐答案

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

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.

示例

Example on jsFiddle.

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

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

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

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