【问题标题】:Input event triggered on Internet Explorer when placeholder changed占位符更改时在 Internet Explorer 上触发的输入事件
【发布时间】:2014-02-19 18:48:32
【问题描述】:

正如jsfiddle example 所示,当我更改占位符时,它会触发输入事件。我在 IE 11 版本上对其进行了测试,但我猜旧版本也有同样的问题。其他浏览器的行为并非如此。这是 I.E 错误吗?如果是这样,在 I.E 上解决此问题的方法是什么?

这里是 html 标记。

<input type="text" />
<button>Change PlaceHolder</button>

这里是 javascript 部分。

var i = 0;
$('button').click(function(){
  $('input').attr('placeholder','placeholder ' + i++);
});

$('input').bind('input',function(){
    alert('input even occur');
});

【问题讨论】:

标签: javascript html


【解决方案1】:

检查输入是否有焦点就足够了

$('input').bind('input',function(){
    if($(document.activeElement) != $('input'))
        return;
    alert('input even occur');
});

这也“修复”了当占位符包含重音字符时无需任何操作即可触发的输入事件

【讨论】:

  • 嗯,它只修复了部分问题。当您单击文本框时,它会清除触发输入事件的占位符 - 并且控件获得焦点。
  • 确实,但这是另一个问题
  • 当输入值 a 包含“acute”字符时,会出现类似的问题(始终使用 IE 11)。示例
猜你喜欢
  • 2011-07-28
  • 1970-01-01
  • 2011-08-29
  • 2013-10-17
  • 1970-01-01
  • 1970-01-01
  • 2010-12-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多