JavaScript return focus Switching _javascript tips

Source: Internet
Author: User
Copy Code code as follows:

<script language= ' javascript ' for= ' document ' event= ' onkeydown ' >
if (event&&event.srcelement) {
Srcele=event.srcelement;
if (event.keycode| | Event.charcode) ==13 && srcEle.tagName.toUpperCase () = = ' INPUT ' && srcEle.type.toUpperCase () = = ' TEXT ')
eventevent.keycode=event.charcode=9;
}
</script>

If more than one keyboard listener event is registered, although the KeyCode value is modified in the code snippet, the other keyboard listener events are still the original keycode. This is related to the JavaScript event model (remember to start the event propagation from each registered listening event, respectively, along its own route).
Here is the test code:
<ptml> <HEAD> <!--here test jquery's keyboard response is normal--> <script src= "Jquery.js" ></script> <script Src= "Jquery.hotkeys.js" ></script> <script> $ (function () {$ (document). KeyDown (function (evt) {debug ( EVT); }); }); </script> <!--This is the code snippet for the carriage return conversion line--> <script language= ' javascript ' for= ' document ' event= ' onkeydown ' > if (EV ent&&event.srcelement) {srcele=event.srcelement; if (event.keycode| | Event.charcode) ==13 && srcEle.tagName.toUpperCase () = = ' INPUT ' && srcEle.type.toUpperCase () = = ' TEXT ') event.keycode=event.charcode=9; } </script> <script> function Debug (evt) {document.getElementById (' info '). innertext=evt.keycode| | Evt.charcode; } </script> </HEAD> <BODY> <input type=text onkeydown= "Debug (event);" > <input type=text> <input type=text> <input type=text> <input type=button value= "button" & Gt Key code: <span id=info></span> &Lt;/html>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.