Solve IE7 error "input type = file" to restart fire twice?

You encountered this IE7 error:

<input type="file" id="xxx">

<script> 
     $('#xxx').change(function(){ alert(1) })
</script>

when I click on the input and select the file, it appears for the first time. Then I click on an empty area on the body, the warning appears again. This happens even when I bind the change event to input: a file with JQuery 1.6 (the last time at the moment).

How can I prevent this in the easiest way? Thanks for all the suggestions!

+5
source share
2 answers

This is what I did after some hard hours of brainstorming:

$('input:file').click(
    function(){
         $(this).one(
              'change',
              function(){ alert(1) /*do stuff here*/ }
         )
    }
)

, , "change" . , , .

, ! .

+6

,

0

All Articles