Any alternative to jQuery change() to detect when user selects new file via dialog box in IE8?

前端 未结 3 473
不知归路
不知归路 2020-12-11 07:56

I am unable to detect when input type=\"file\" changes its value after user selects file and the dialog box closes.

$(\'.myInput\').change(function(){
    a         


        
相关标签:
3条回答
  • 2020-12-11 08:31

    Edit - Nick is right, it's fixed in 1.4.2. http://jsfiddle.net/7wR2L/

    You can detect click and keep track of it's last value. Something like..

    $('.myInput').click(function() {
       var $file = $(this);
       if( $file.val() != $file.data('lastVal') ) {
         // different
       }
       $file.data('lastVal', $file.val() );
    });
    
    0 讨论(0)
  • 2020-12-11 08:32

    Dan Heberden's comment about updating to 1.4.2 works.

    However if another element is used to trigger the file file selection, the file input element no longer registers a "change" event.

    The new question I created for this has a fork your fiddle to illustrate this case. See jQuery: "change" event on file input element does not fire if the file selection is triggered by an element other than the file input for details.

    0 讨论(0)
  • 2020-12-11 08:40

    This was a known bug that was resolved as part of the jQuery 1.4.2 release, 1.4.2 got a major event model re-write and this was fixed as part of that, just upgrade to resolve the problem :)

    0 讨论(0)
提交回复
热议问题