Home >Web Front-end >HTML Tutorial >How to achieve focus jump in textbox by pressing Enter key? _html/css_WEB-ITnose

How to achieve focus jump in textbox by pressing Enter key? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:45:431163browse

Question:
When I press the Enter key in the username textbox, how can the focus jump to the password textbox?


Reply to discussion (solution)










Username:
Password:




<script> <br> var usernameObj = document.getElementById("username"); <br> usernameObj.onkeydown = function(event) { <br> e = event ? event :(window.event ? window.event : null); <br> // Press Enter key and the input box value is not empty <br> if(e.keyCode==13 && usernameObj.value){ <br> document.getElementById("password").focus(); <br> } <br> } <br> </script>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn