IE10 oninput事件屡屡引发了对重定向

问题描述 投票:1回答:3

重定向一个“oninput”事件的网页时(没有等价问题使用Chrome时),我一直在经历着一个奇怪的问题,IE10。我已经产生了仍表现出该问题的代码的最删节过的版本,如下所示:

<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,当(通过双击或通过Apache)浏览此代码在我的Windows 7 PC多次重定向仿佛初始化输入文本框本身的价值的行为是产生立即“oninput”事件。但是,当我改变从“£”标志的字母“A”的初始文本框中输入值,不会出现重复的重定向。

我第一次注意到这个问题作为一个项目我工作的一部分。在这种情况下,用户的输入是否造成延迟刷新页面,开始反复重定向时,我进入了一个“£”符号。正如我所说,上面的代码是我在试图跟踪什么导致问题产生的最削减的版本。

没有任何人遇到这种使用IE10?如果是这样,任何人都可以解释为什么IE10是表现这种方式?

javascript-events internet-explorer-10 url-redirection
3个回答
2
投票

我发现,似乎表明,这可能是在IE10中的错误如下:

social.msdn.microsoft.com: Event oninput triggered on page load

此外,还有一个后续的错误报告(与上面的页面中):

connect.microsoft.com: onInput event fires on loading the page when input @value is non-ASCII

编辑补充:在页面的底部指向第二个环节,有什么似乎是从微软指出,他们无法重现bug描述无益的答复,所以它可能是前一段时间的问题已经解决...


0
投票

有anoter错误报告,仍然是开放的:

http://connect.microsoft.com/IE/feedback/de...


0
投票

对于任何人谁可能会遇到这种情况,可以用这个“类”作为一种替代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);
});

调用myInputChangeWatcher.toggleFieldWatching()在onfocus和的onblur输入事件

© www.soinside.com 2019 - 2024. All rights reserved.