最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - input file onchange event not being fired in chrome - Stack Overflow

programmeradmin2浏览0评论

This is a weird thing i noticed in chrome. if the user select a file and then select the same file again bu opening the file dialog again, chrome doesn't fire the onchange event while firefox does.

anybody noticed it as well?

This is a weird thing i noticed in chrome. if the user select a file and then select the same file again bu opening the file dialog again, chrome doesn't fire the onchange event while firefox does.

anybody noticed it as well?

Share Improve this question edited Oct 2, 2011 at 9:30 Bohemian 425k100 gold badges599 silver badges745 bronze badges asked Jul 8, 2011 at 10:41 AmirAmir 1,2593 gold badges18 silver badges32 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 6

This is a known feature of Chrome and a quick Google on the topic will bring up some interesting discussions.

It makes sense to me that the change event wouldn't fire since nothing has changed (you're selecting the same file)

As for your question, what exactly are you asking? Are you looking for a way to change this behaviour or do you just want to know if we've noticed this as well?

If you want a way around this behaviour you can simply create a new file input in your Javascript and replace the previous one. This way your change event is guarenteed to fire.

function resetFileInput($element) {
  var clone = $element.clone();
  $element.replaceWith(clone);
}

And then use:

$('#element_id').on('change', function(){
...
});

Worked well for me!

An easier solution to reset an input file that works well for me :

document.getElementById('idOfInput').value = '';
发布评论

评论列表(0)

  1. 暂无评论