占位符更改时在Internet Explorer上触发输入事件 [英] Input event triggered on Internet Explorer when placeholder changed
本文介绍了占位符更改时在Internet Explorer上触发输入事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如此 jsfiddle示例所示,当我更改占位符时,它将触发输入事件.我在I.E 11版本上进行了测试,但我猜旧版本也有同样的问题.其他浏览器的行为与此不同.这是I.E错误吗?如果是这样,那么在I.E上解决此问题的方法是什么?
As it is shown in this jsfiddle example when i change placeholder it triggers input event. I tested it on I.E 11 version but i guess that older versions have same problem. The other browsers does not behave like this. Is this I.E bug ? If so what is workaround for this problem on I.E ?
这是html标记.
<input type="text" />
<button>Change PlaceHolder</button>
这是javascript部分.
And here is javascript part.
var i = 0;
$('button').click(function(){
$('input').attr('placeholder','placeholder ' + i++);
});
$('input').bind('input',function(){
alert('input even occur');
});
推荐答案
检查输入是否重点突出
$('input').bind('input',function(){
if($(document.activeElement) != $('input'))
return;
alert('input even occur');
});
这还修复"了占位符包含重音字符时触发的输入事件,而无需执行任何操作
this also "fixes" the input event being triggered without any actions when placeholder contains an accented character
这篇关于占位符更改时在Internet Explorer上触发输入事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文