Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

internet explorer - jQuery: "change" event on file input element does not fire if the file selection is triggered by an element other than the file input

RE:


The above questions dealt with getting the 'change' event to fire consistently across browsers after a file selection has been made. This is has been resolved as evidenced by the example at http://jsfiddle.net/7wR2L/

My situation is a tad different. It seems this issue rears its ugly head in another context.

Based on design constraints, I have to use a non-file-input element ('a' tag) to trigger the "click" event on the file input element. So far from my tests, it looks like the file input is unable to fire a "change" notification when a file is selected in this way.

Please take a look at the example at http://jsfiddle.net/rudylattae/7wR2L/8/

Test environment(s):

Windows Server 2008 R2

  • Chrome 7.0.517.44 - PASS
  • Firefox 3.6.9 - FAIL
  • IE 8.0.7600.16385 64bit - FAIL

Windows XP Pro (2002 - SP3)

  • Chrome 8.0.552.28 beta - PASS
  • Firefox 3.5.14 - FAIL (does not even trigger the file selector)
  • IE 8.0.6001.18702 - FAIL
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With MSIE use the onpropertychange-Event, example: http://jsfiddle.net/7wR2L/14/

As jQuery does'nt support this event you have to assign it without jquery(inline or use attachEvent )

In other browsers try using mutation-events, maybe they'll work there. See a related topic on mutation-events from yesterday, to have a little example how they work: How to capture change on page title from a firefox extension


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...