Home > front end > Excuse me: function handleEnter {(field, the event) in the field?
Excuse me: function handleEnter {(field, the event) in the field?
Time:11-03
The following code:
The function handleEnter (field, the event) { Var keyCode= event. KeyCode? Event. KeyCode: event. Which? Event. Which: event. CharCode; If (keyCode==13) { Var I; For (I=0; I & lt; Field, the form elements. Length; I++) If (field==field. Form. Elements [I]) break; I=(I + 1) % field. The form. Elements. Length; Event. The preventDefault (); Field, form elements [I]. Focus (); return false; } The else return true; }
Excuse me: 1, what is that field? 2, event. KeyCode? Event. KeyCode: event. Which? Event. Which: event. CharCode; What is the meaning of ?
CodePudding user response:
1 field is parameters, specific what is it, to see your incoming outside what arguments, 2 event is an event object, event. The keyCode is corresponding to the ASCII keyboard events of buttons, Event. The keyCode? Event. KeyCode: event. Which? Event. Which: event. CharCode; Is three unary, if? Question mark in front of the expressions established, then take a colon: former values, or take a colon: after values, Var keyCode= event. The keyCode ? event. The keyCode : (event. Which? Event. Which: event. CharCode) ; Is red, blue value, otherwise take green value (including the value of the green is a ternary operators, spread out the green value according to the three unary) Is equivalent to the following if the else Var keyCode. If (event. KeyCode) { KeyCode=event. KeyCode; {} else if (event which) KeyCode=event. Which; } else { KeyCode=event. CharCode; }