![](/img/trans.png)
[英]Why is onclick for the first button in a form triggered when I hit ENTER key (and no keyCode in event)?
[英]check and uncheck the control without using the mouse,as when we hit enter key the button control gets triggered
目前,我有一个html设计,其中有一个文本框和一个按钮..按Enter键入id后,页面将被重定向,但同时也有一个复选框控件。
我的问题是:
是否有任何选项可以在不使用鼠标的情况下检查和取消选中控件,因为当我们按Enter键时,按钮控件将被触发
对于更多的想法,我给了gmail登录窗口,其中包含一个文本框和复选框
无论页面上“ Enter”出现在何处,都将单击该按钮:
$(document).keypress(function(e){
if (e.which == 13){
$("#Your_Submit_Button_ID").click();
}
});
按下Enter键将触发您当前专注于的表单的提交按钮。 按Tab键会将焦点从一个字段转移到另一个字段,但Enter键将始终触发表单的提交按钮。
但是,您可以在按下Enter键时捕获按键并执行检查/取消检查,而不是默认触发器。
$("form").keypress(function (e) {
if(e.keyCode === 13) {
e.preventDefault();
// code that check/uncheck your checkbox
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.