Javascript determines whether to press the enter key and resolves the differences between browsers
- 2020-03-30 02:58:07
- OfStack
<li class="item pin">
<span class="overlabel" style="display: block;"> Please enter the verification code </span>
<input type="text" class="txt" id="checkNum" name="checkNum" maxlength="4" onkeydown="keyboardEvent(event);" />
<img src="${basePath}/randomImageCodeStyle" width="60" height="28" id="chkNum" title=" Click reload the verification code " style="cursor: hand" />
</li>
//Listen for the Enter key to automatically commit events
function keyboardEvent(event){
var keyCode=event.keyCode ? event.keyCode:event.which?event.which:event.charCode;//Resolve differences between browsers
if(keyCode==13){
submitForm();
}
}
JQuery drops the standard button attribute and USES which, which is a bit confusing.
Which was introduced by Firefox and not supported by IE. Which means to get the keyCode of the keyboard.
Which in jQuery can be either a keyboard key or a mouse key.