JQuery keyup not working IE 10

2019-07-20 07:31发布

问题:

This code works perfectly on chrome and firefox. It only messes up on IE 10. I am using JQuery 1.11.1. In the console it appears that the keyup is not fired if you user two keys. So if I hold "alt" + "a" it will only fire the "a" keyup when I release them. In chrome and firefox it will fire both. I did not test on a earlier version of IE only 10. Also I could not get JSfiddle to work properly, I do not know how to use functions correctly in the JSfiddle.... So i am sorry :(. But here is the code. (alt Keys are being used).

jQuery( document ).ready(function(){
 var altKey = false;
    function addCheckAlt(){
        jQuery(document).bind("keydown", function(e){
           if(e.keyCode === 18)
               altKey = true;
        });

        jQuery(document).bind("keyup", function(e){
           if(e.keyCode === 18)
               altKey = false;
        });
    }

   function checkIfAltKey(event){
      if(altKey){
         event.preventDefault();
         altKey = false;
         return false;
      }
      else{
         altKey = false;
         return true;
      }
    }
}

HTML

<input
            type="button"
            class="btn btn-info helpBtn"
            onclick="if(checkIfAltKey(event))alert('hi');"
            value="Help"
            accesskey="6"
            title="Help (access key 6)"/>

when using this code just use alt + 6 and it will do a click event and click the button. If anyone can give me an idea of how to go about this at this point that would be great!! (All it does is if the alt key is being pressed then it will not do the alert)

回答1:

I got it working by adding the next code inside the document ready function:

$("#TextBoxName").keyup(function () {
        debugger;
        return true;
    });

Hope it helps anyone that comes here like I did, with the same problem. This works on Chrome 47.0.2526.111 and IE 11.