alternate to onchange event in <input type='file' />

前端 未结 8 1959
青春惊慌失措
青春惊慌失措 2020-12-10 04:04

Seems really a simple thing but can\'t figure it out. I\'ve been using the onchange event on element and it works well. Once the user browses and selects a file, I get the

相关标签:
8条回答
  • 2020-12-10 04:41

    You could have the choose file button clear the contents of the input onclick, that way even even if they choose the same file your event will still trigger. Of course, then your onchange handler will have to check for blank values, but it should probably be doing something similar or more anyway if it's going to use that value to upload a file...

    0 讨论(0)
  • 2020-12-10 04:41

    You could not fire change event second time on the file input, but you can fire change event on the span. Below works in chrome and ff. I didn't check in IE. $('#change_span').bind('change',function(){ alert($('#file_1').val()) })

    <span id='change_span'><input id="file_1" type="file"></span>

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