[英]Activate Submit Button on Enter
現在,我必須單擊“ Login
按鈕才能將表單發送到服務器。
我想在密碼字段上按Enter鍵。
這是代碼:
<%@ Page Language="VB" AutoEventWireup="False" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Login Page</title>
<SCRIPT language="javascript" src="commonpages/js/Utility.js" type="text/javascript"></SCRIPT>
<script>
function GoBtn_ServerClick(oButton, oEvent) {
}
</script>
</head>
<body style="background-color:AliceBlue">
<div id="main0">
<!--<input id="auto" type=button value="Print test" onclick="Printtest();">-->
<table width=800 align=center height=600px style="background-color: AliceBlue;">
<tr>
<td width=25></td>
<td width=750 align=center><form runat="server">
<table ><tr><td colspan="2">
</td></tr>
<tr><td align=left>
Login:</td><td align=right>
<input id="login" runat=server type=text style="width: 100px"/></td>
</tr><tr><td align=left>
Password:</td><td align=right>
<input id="pw" runat=server type=password style="width: 100px"/>
</td></tr>
<tr><td align=center colspan=2>
<input type=button runat=server id=GoBtn value=Login style="width: 60" CausesValidation="False" />
</td></tr></table></form>
</td>
<td width=25></td>
</tr>
</table>
</div>
</body>
</html>
我已經在Stack Overflow上搜索了類似的問題,但是它們顯示了使用ASP控件而不是HTML控件的示例。
在GoBtn上將'type = button'更改為'type = submit',當您按Enter鍵時應觸發該按鈕。
或者,當在“密碼”字段中按Enter鍵時,可以使用jQuery'單擊'按鈕:
$(document).ready(function(){
$('#pw').keypress(function(e){
if(e.keyCode==13)
$('#GoBtn').click();
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.