重定向时反复触发IE10 oninput事件
IE10 oninput event repeatedly triggered on redirection
我在IE10中遇到了一个奇怪的问题,当在'oninput'事件上重定向页面时(使用Chrome时没有类似的问题)。我已经生成了仍然显示问题的代码的最精简版本,如下所示:
<html>
<head>
<script type="text/javascript">
function onChangeInputText()
{
window.location.href = "oninput_problem.html"; // Back to this page.
}
</script>
</head>
<body>
<input type="text"
oninput="onChangeInputText()"
value="£"
/>
</body>
</html>
在我使用IE10的Windows 7 PC上,这段代码在浏览时(通过双击或通过Apache)反复重定向,好像初始化输入文本框本身的值的行为正在立即生成'oninput'事件。但是,当我将初始输入文本框的值从'£'符号更改为字母' a '时,重复的重定向不会发生。
我第一次注意到这个问题是在我正在做的一个项目的一部分。在这种情况下,用户的输入应该导致延迟的页面刷新,当我输入"£"符号时,页面开始反复重定向。正如我所说,上面的代码是我在试图跟踪导致问题的原因时产生的最精简的版本。
有人在使用IE10时遇到过这种情况吗?如果是这样,谁能解释一下为什么IE10是这样的?
我发现了以下显示这可能是IE10的一个bug:
social.msdn.microsoft.com:页面加载触发oninput事件
还有一个后续的bug报告(在上面链接的页面中):
connect.microsoft.com: onInput事件在加载页面时触发当输入@value是非ascii
编辑补充:在第二个链接指向的页面底部,有一个似乎是来自微软的无用回复,声明他们无法重现所描述的错误,因此问题可能需要一段时间才能修复…
还有一个bug报告还在打开:
http://connect.microsoft.com/IE/feedback/de..。
对于可能遇到这种情况的人,您可以使用这个"类"作为onInput事件的替代。
const getFieldWatcherInstance = (function(watchedElement, onElementValueChange){
let intervalReference = null;
let lastValue = null;
if(!watchedElement instanceof Element) return new Error('watchedElement is not an HTML Element');
if(typeof onElementValueChange !== 'function') return new Error('onElementValueChange is not a function');
return {
toggleFieldWatching : function(){
if(intervalReference){
clearInterval(intervalReference);
intervalReference = null;
}
else{
intervalReference = setInterval(function(){
const currentValue = watchedElement.value;
if(lastValue !== currentValue){
onElementValueChange(currentValue);
lastValue = currentValue;
}
}, 100);
}
}
};
});
设置如下:
const myInputChangeWatcher = getFieldWatcherInstance(<**insert real element reference here**>, function(newValue){
console.log('The new value is: ' + newValue);
});
在输入
- 在不阻止默认行为的情况下检测IE10中的缩放
- WebComponentsJS with IE10
- 是否可以为HTML5输入滑块触发oninput事件
- 链接上的IE10 jquery句柄单击事件不起作用
- Console.debug在ie10中不工作
- SCRIPT438:对象没有't支持属性或方法'endsWith'在IE10中
- IE10+11:XSLT转换将任意CR/LF添加到XML中
- 框架集+列IE10
- IE9+IE10 AJAX调用不起作用
- 与wavesurfer.js成角度;我不在IE10工作
- jQuery Ajax cors IE10 not working
- IE10和11,jQuery的意外行为动画化和溢出
- IE10中的画布元素Squished
- 角度$scope在IE10中不刷新
- chrome setSelectionRange()在oninput处理程序中不起作用
- 由于浏览历史设置,angularjs http.get调用未在ie10中启动
- 将oninput与CodeMirror一起使用
- jPlayer和IE10-SCRIPT438:对象没有't支持属性或方法'jPlayer'
- video.js,播放视频,但在IE10上没有声音
- 重定向时反复触发IE10 oninput事件