1

I have a HTML input that must call a JS function when a key is pressed.

It works fine in Firefox, Chrome, and some versions of IE. It depends of the document mode of IE:

  • Explorer mode: 10. Document mode: Standards. Works? YES
  • Explorer mode: 10. Document mode: IE 8 standards. Works? NO (default config for IE10)
  • Explorer mode: 9. Document mode: IE 9 standards. Works? YES
  • Explorer mode: 8. Document mode: IE 8 standards. Works? YES

HTML code:

<input type="text" id="txtSearch" onkeypress="LaunchSearch(event);"/>

JS code:

function LaunchSearch(e) {
   if (e.keyCode == 13) {
       if ($.browser.msie  && parseInt($.browser.version, 10) <= 8) {
           e.returnValue = false;
       } else {
           e.preventDefault();
       }
       Search();
   }
}

Anyone has any idea?

4

0 回答 0