输入登录表单的密钥

发布于 2024-09-04 23:55:06 字数 122 浏览 0 评论 0原文

我的网站上有一个搜索表单和一个登录表单。当登录表单具有焦点时按下 Enter 按钮时,将运行搜索而不是登录。有办法解决这个问题吗?

我已经尝试在登录表单周围使用面板并使用默认按钮,但是当我这样做时,登录视图会出错。

I have a search form and a login form on my website. When the enter button is pressed when the login form has focus, the search runs instead of the login. Is there a way to fix this?

I've already tried using a panel around the login form and use defaultbutton, but the loginview errors when I do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

卷耳 2024-09-11 23:55:06

您可以尝试在登录表单上设置按键事件。在我的脑海中,

$('#loginForm').keypress(function (e) {
  if(e.keyCode=='13') //Keycode for "Return"
     $('#login').click();
  }
});

假设您为所涉及的元素提供了适当的 ID,类似的东西应该可以工作。

You could try setting up a keypress event on your login form. Off the top of my head, something like

$('#loginForm').keypress(function (e) {
  if(e.keyCode=='13') //Keycode for "Return"
     $('#login').click();
  }
});

should work, assuming you give appropriate IDs to the elements involved.

逆光飞翔i 2024-09-11 23:55:06

如果您谈论的是 HTML,则 建议使用 Tab 键顺序(在此处了解更多信息)相关或表单创建的顺序,行为取决于用户代理。

If you're talking about HTML, then this suggests tab order (learn more about that here) is relevant or the order in which the forms were created, the behavior depending on the user agent.

烟火散人牵绊 2024-09-11 23:55:06

您可以尝试在运行时添加像这样的属性

Login loginControl = (Login)lvLoginView.FindControl("logLogin"); 
TextBox tbUserName = (TextBox)loginControl.FindControl("UserName");
TextBox tbPassword = (TextBox)loginControl.FindControl("Password");
Button loginButton = (Button)loginControl.FindControl("LoginButton");  
tbUserName.Attributes["onKeyPress"] = "KeyDownHandler('" + loginButton.ClientID + "')";
tbPassword.Attributes["onKeyPress"] = "KeyDownHandler('" + loginButton.ClientID + "')";

和一些 JS:

function KeyDownHandler(btn){  
// process only the Enter key  
if (event.keyCode == 13)  {    
// cancel the default submit  
  event.returnValue = false;  
  event.cancel = true;   
  var obj = document.getElementById(btn);   
  obj.click();  
}}

UPDATE

自动转换为 VB.NET 由 telerik 提供

Dim loginControl As Login = DirectCast(lvLoginView.FindControl("logLogin"), Login)
Dim tbUserName As TextBox = DirectCast(loginControl.FindControl("UserName"), TextBox)
Dim tbPassword As TextBox = DirectCast(loginControl.FindControl("Password"), TextBox)
Dim loginButton As Button = DirectCast(loginControl.FindControl("LoginButton"), Button)
tbUserName.Attributes("onKeyPress") = "KeyDownHandler('" + loginButton.ClientID + "')"
tbPassword.Attributes("onKeyPress") = "KeyDownHandler('" + loginButton.ClientID + "')"

could you try adding attributes at run time like this

Login loginControl = (Login)lvLoginView.FindControl("logLogin"); 
TextBox tbUserName = (TextBox)loginControl.FindControl("UserName");
TextBox tbPassword = (TextBox)loginControl.FindControl("Password");
Button loginButton = (Button)loginControl.FindControl("LoginButton");  
tbUserName.Attributes["onKeyPress"] = "KeyDownHandler('" + loginButton.ClientID + "')";
tbPassword.Attributes["onKeyPress"] = "KeyDownHandler('" + loginButton.ClientID + "')";

and some JS:

function KeyDownHandler(btn){  
// process only the Enter key  
if (event.keyCode == 13)  {    
// cancel the default submit  
  event.returnValue = false;  
  event.cancel = true;   
  var obj = document.getElementById(btn);   
  obj.click();  
}}

UPDATE

Auto-converted to VB.NET courtesy of telerik

Dim loginControl As Login = DirectCast(lvLoginView.FindControl("logLogin"), Login)
Dim tbUserName As TextBox = DirectCast(loginControl.FindControl("UserName"), TextBox)
Dim tbPassword As TextBox = DirectCast(loginControl.FindControl("Password"), TextBox)
Dim loginButton As Button = DirectCast(loginControl.FindControl("LoginButton"), Button)
tbUserName.Attributes("onKeyPress") = "KeyDownHandler('" + loginButton.ClientID + "')"
tbPassword.Attributes("onKeyPress") = "KeyDownHandler('" + loginButton.ClientID + "')"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文