您的位置:首页 > 其它

空格键和enter键的事件处理(页面存在多个按钮,登陆按钮不是页面的第一个按钮)

2009-10-23 09:34 260 查看
<script type="text/javascript">

function keydown(e)

{

if(e.keyCode===13)

{

if(window.event) //IE浏览器

{e.returnValue=false;}

else //FireFox浏览器

{e.preventDefault();}

document.getElementById('ctl00_ContentPlaceHolder2_submit').click(); // ctl00_ContentPlaceHolder2_submit为submit登陆按钮的客户端名称

}

}

</script>

html:

在需要触发事件的控件上,添加onkeydown,例如:

账号:<asp:TextBox ID="username" runat="server" onkeydown="keydown(event);"></asp:TextBox>

密码:<asp:TextBox ID="pwd" runat="server" TextMode="Password" onkeydown="keydown(event);"></asp:TextBox>

登陆按钮:<asp:ImageButton ID="submit" runat="server" ImageUrl ="xxx.gif" alt="登陆按钮" onkeydown="keydown(event);" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: