简体   繁体   English

Internet Explorer 8按下按钮之间的延迟

[英]Internet Explorer 8 delay between pressing the button

Need to quickly press a button to +1 to the value. 需要快速按下一个按钮以+1到该值。

<html>
<head>
<script>
   var a = 2;
   function update() {
   document.getElementById('change').innerHTML = a;
   a++;}
</script>
</head>
<body>
<div id="change">1</div>
<input type="button" onclick="update()" value="TEST">
</body>

When I click on the button very quickly, there is a delay. 当我快速单击按钮时,会有延迟。 For example, a button has been pressed ten times, but value is 6. 例如,一个按钮已被按下十次,但值为6。

In other browsers everything works correctly. 在其他浏览器中,一切正常。

Maybe the problems is an event called "ondblclick" for internet explorer. 也许问题出在互联网浏览器上,这是一个称为“ ondblclick”的事件。

You can try the solution from this question to remove that event: 您可以尝试从以下问题中解决问题,以删除该事件:

Remove OnDblClick Event on Item using jQuery 使用jQuery删除Item的OnDblClick事件

There is definitely a latency issue in Internet Explorer 8. Somewhat in line with what Oscar stated in his answer, the dblclick event may be eating up some of the clicks. Internet Explorer 8中肯定存在延迟问题。与Oscar在他的回答中所说的有些dblclickdblclick事件可能正在吞噬某些点击。 If this were the case, we could expect that incrementing during that even would eradicate the problem. 如果是这种情况,我们可以期望在此期间增加甚至可以消除问题。 Sure enough, that's what we find when we handle that event as well. 当然,这也是我们处理该事件时发现的。

(function () {

    "use strict";

    var clicks = 0,
        result = document.getElementsByTagName( "label" )[0],
        button = document.getElementsByTagName( "button" )[0];

    if ( button.addEventListener ) {
        button.addEventListener( "click", increment );
    } else if ( button.attachEvent ) {
        button.attachEvent( "onclick", increment );
        button.attachEvent( "ondblclick", increment );
    }

    function increment () {
        result.innerHTML = ++clicks;
    }

}());

The problem doesn't appear to exist with versions of IE that support the addEventListener method (Internet Explorer 9 and up). 支持addEventListener方法的IE版本(Internet Explorer 9及更高版本)似乎不存在此问题。 As a result, we really only appear to need the double-binding in version 8 and below. 结果,我们真的只需要在版本8和更低版本中进行双重绑定。

Fiddle: http://jsfiddle.net/vapv60jw/1/ 小提琴: http : //jsfiddle.net/vapv60jw/1/

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM