日期:2014-05-16  浏览次数:20443 次

JS控制网页中的回车键

<input name="username" type="text" size="20" value="" onkeydown="enterkey(this.name)" />

?

<input id="password" name="password" type="password" size="20" value="" onkeydown="enterkey(this.name)"/>

?

<input id="validation" name="checkCode" type="text"
?????????class="input" style="width: 60px;" onkeydown="enterkey(this.name)" />
????????<img alt="验证码" width=60 height=22 align="absmiddle" border="0"
?????????src="<%=contextPath %>/CheckCode"? />

?

<a href="javascript:void(false);" id="login"
???? onClick="javascript:loginF();"><img name="loginbtn1" src="<%=contextPath%>/jsp/portal/images/loginbtn1.jpg" width="80" height="20" border="0" alt=""></a>?? //登录按钮由图片构成

?

function enterkey(ctrname) {
??? try? {
??????? var el_keydown=window.event.srcElement;
??????? if(event.keyCode==13)
??????? {
??????????? if ("checkCode" != ctrname) {
??????????????? window.event.keyCode=9;?? //相当于TAB键作用(输入完一行按回车,跳到下一行)
??????????? }else if ("checkCode" == ctrname) {
??????????????? loginF();
??????????? }
??????? }
??? }catch(e) {
??????? return;
??? }
}