如下的一個登陸:
<script>
function KeyP() {
if (event.keyCode == 13 ){
document.getElementById('Btn_DengL').click();
}
}
</script>
<table width="300" align="center" class="tb">
<tr>
<th scope="col">用戶名:</th>
<th scope="col"><input id="userid" type="text" size="20" class="textbox_style" style="height:15px;width:146px" οnkeypress="KeyP()" />
<input id="none" type="hidden" value=""/>
</th></tr>
<tr><th scope="col">密 碼: </th>
<th scope="col"><input id="password" type="password" size="20" style="height:15px;width:146px" class="textbox_style" οnkeypress="KeyP()" /></th></tr>
<tr>
<td></td><td>
<img alt="" src="~/images/186X/login.gif" runat="server" id="Btn_DengL" οnclick="DengLClick()" style="cursor:hand"/>
<img alt="" src="~/images/186X/reg.gif" runat="server" id="Btn_Reg" οnclick="GoReg()" style="cursor:hand"/>
</td></tr>
</table>
不管焦點在用戶名、密碼還是登陸按鈕上,按Enter時,都會觸發登陸按鈕事件