First, let's look at the effect of the following example:
<Input type = "text" NAME = ""> <br>
<Input type = "text" NAME = ""> <br>
<Input type = "text" NAME = ""> <br>
<Input type = "text" NAME = ""> <br>
<Input type = "text" NAME = ""> <br>
<Input type = "text" NAME = ""> <br>
<Input type = "text" NAME = ""> <br>
<Input type = "text" NAME = ""> <br>
<Script language = "javascript" for = "document" event = "onkeydown">
<! --
If (event. keyCode = 13)
Event. keyCode = 9;
-->
</Script>
Principle:
How to move the focus of the text box one by one with the "Enter key". Three methods are provided. The best one is as follows:
Use a client script to add the onkeydown event of the document to the page. After receiving the carriage return event, the page performs the Tab key function. That is, you only need to change the keyCode of the event from 13 to 9.
VBScript code:
<Script language = "vbscript">
Sub document_onkeydown
If event. keyCode = 13 then
Event. keyCode = 9
End if
End sub
</Script>
The Javascript code is as follows:
<Script language = "javascript" for = "document" event = "onkeydown">
<! --
If (event. keyCode = 13)
Event. keyCode = 9;
-->
</Script>
In this way, the focus can be moved down, but the buttons also play the same role. Generally, after entering the information, the customer jumps to the button, it is best to directly press "enter" to submit data. therefore, do not focus on the "Submit" button when modifying the preceding method. and directly activate the submission.
Therefore, I modified the preceding code to determine whether the event "Source" is a submit button. The Code is as follows:
<Script language = "javascript" for = "document" event = "onkeydown">
<! --
If (event. keyCode = 13 & event. srcElement. type! = 'Button '& event. srcElement. type! = 'Submit '& event. srcElement. type! = 'Reset' & event. srcElement. type! = 'Textea '& event. srcElement. type! = '')
Event. keyCode = 9;
-->
</Script>
Determines whether it is a button because there is type = "button" in HTML"
Determines whether it is a submit because there is type = "submit" in HTML"
Determines whether it is a reset because the "reset" on HTML should be executed.
Whether it is null is determined because the "<a> link" on HTML should also be executed. This situation does not happen much, you can use "tabindex =-1" to cancel the link and obtain the focus.