Am using html input textbox in .aspx page, when i change values in that textbox and hit enter key means page get postback. How to prevent this postback other than returning false in "onkeypress" event.
我在.aspx页面中使用html输入文本框,当我更改该文本框中的值并按Enter键意味着页面获得回发。除了在“onkeypress”事件中返回false之外,如何防止此回发。
Code:
textBox[0].setAttribute("onkeydown", "return (event.keyCode!=13);");
Thanks,
Karthik.
1 个解决方案
#1
9
You need to use javascript to prevent the default behaviour of clicking enter, which is to submit the form. You need to do something like this (and I'm using jQuery here, which is included by default with an ASP.Net app):
您需要使用javascript来防止单击enter的默认行为,即提交表单。你需要做这样的事情(我在这里使用jQuery,默认包含在ASP.Net应用程序中):
$('input[type="text"]').keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
#1
9
You need to use javascript to prevent the default behaviour of clicking enter, which is to submit the form. You need to do something like this (and I'm using jQuery here, which is included by default with an ASP.Net app):
您需要使用javascript来防止单击enter的默认行为,即提交表单。你需要做这样的事情(我在这里使用jQuery,默认包含在ASP.Net应用程序中):
$('input[type="text"]').keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});