解决IE7错误“输入类型=文件”换火两次? [英] Solve IE7 bug "input type=file" onchange fire twice?
问题描述
< input type =fileid =xxx>
< script>
$('#xxx')。change(function(){alert(1)})
< / script>
当我点击输入&选择一个文件,alertbox第一次显示。然后我点击身体上的空白区域,警报框再次显示。即使我将更改事件绑定到使用JQuery 1.6输入:文件(此时最后一个)。
如何以最简单的方式阻止这种情况?感谢所有的建议!
这是我经过一些艰苦的脑风暴之后所做的: >
$('input:file')。点击(
function(){
$(this) (
'change',
function(){alert(1)/ * do stuff here * /}
)
}
)
每次用户单击输入选择文件时,我们将事件更改绑定一次。所以每次用户想要选择一个文件时,事件都会触发一次。
感谢上帝!谢谢大家。
Did you ever face this IE7's bug:
<input type="file" id="xxx">
<script>
$('#xxx').change(function(){ alert(1) })
</script>
when I click the input & pick a file, the alertbox shows the first time. Then I click on the blank area on the body, the alertbox shows once again. This happens even when I bind the change event to input:file with JQuery 1.6 (lastest at this moment).
How could I prevent this by the simplest way? Thanks for all suggestions!
This is what I've made after some hard hours of "brain storming" :
$('input:file').click(
function(){
$(this).one(
'change',
function(){ alert(1) /*do stuff here*/ }
)
}
)
Each time user click the input to choose file, we bind the event "change" one time with it. So the event fires exactly once everytime user want to pick a file.
And thanks god it works ! Thank you all.
这篇关于解决IE7错误“输入类型=文件”换火两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!