更改占位符会触发IE 10中的输入事件 [英] Changing placeholder triggers input event in IE 10

查看:73
本文介绍了更改占位符会触发IE 10中的输入事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的我遇到了一个奇怪的问题,导致我的代码无限循环。我有以下一点jQuery:

Okay I've run into a strange problem which is causing my code to loop infinitely. I have the following bit of jQuery:

var geoInput = $('#Geo').on('input', function() {
  _this._controller.update({
    geo: this.value
  });
}).get(0);

你可以看到它只是一个基本的事件监听器,它在我的控制器中调用一个更新功能。在更新功能结束时,是一种广播 geoInput 字段进行更新的方法。这由以下内容处理:

As you can see it's just a basic event listener and it's calling an update function in my controller. At the end of the update function is a method which broadcasts for the geoInput field to update. This is handled by the following:

geoInput.receive = function(formState) {
  this.value = formState.geo;
  this.placeholder = _this._placeholders.geo;
}

出于某种原因

this.placeholder = _this._placeholders.geo; 

触发该字段的输入事件。您可以看到这会产生问题,因为这会产生无限循环。我确定这就是正在发生的事情,因为当我在该行之前返回时,循环不会发生。另外,如果我改为说, keyup 事件,则循环也不会发生。

is triggering the input event on that field. You can see how this can be problematic as this creates an infinite loop. I'm sure this is what's happening because when I return before that line the loop doesn't occur. Also, if I change to say, a keyup event, the loop also doesn't occur.

为什么会发生这种情况,我该如何解决?

Why is this happening and how can I fix it?

我已经看了好几个小时并做了不少搜索徒劳无功。此代码在Chrome和FF中按预期工作。

I've looked at this for hours and done quite a few searches to no avail. This code works as expected in Chrome and FF.

推荐答案

有趣的是,如果您只是添加项目,则会发生INPUT事件INPUT属性placheholder或拉丁字母以外的值。
问题IE10和IE11

The funny thing is that the INPUT event occurs if you just add an item to the INPUT attributes placheholder or value other than the Latin alphabet. It's problem IE10 and IE11

var $input = $('<input type="text" placeholder="Бубу"/>');
//or
var $input = $('<input type="text" value="世界へようこそ"/>');
$input.on('input',function(){
    alert('input even occur');
});

这篇关于更改占位符会触发IE 10中的输入事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆