输入用户名及密码点击enter只接登录,功能代码如下:
页面
<asp:TextBox ID="txtUserName" runat="server" Width="150px" onkeydown="return SubmitKeyClick(this,event)"></asp:TextBox>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="150px" onkeydown="return SubmitKeyClick(this,event)"></asp:TextBox>
<input id="btnLogin1" type="button" runat="server" value="登录" onclick="return Checkuser()" />
js代码
function SubmitKeyClick(obj, evt) {
evt = (evt) ? evt : ((window.event) ? window.event : "")
keyCode = evt.keyCode ? evt.keyCode : (evt.which ? evt.which : evt.charCode);
//alert(evt);
//alert(keyCode);
if (keyCode == 13) {
document.getElementById("btnLogin1").focus();
}
本文介绍了一种网页元素的定位方法,并提供了一个利用键盘事件触发登录功能的示例。通过自定义JavaScript函数实现对网页中特定元素的精确定位,同时展示了如何使用ASP.NET中的TextBox组件响应键盘事件来自动提交登录。
1700

被折叠的 条评论
为什么被折叠?



