在网站上输入多个表单的键 [英] Enter key with multiple forms on a website
问题描述
我想要做的是将回车键编程为当某个文本框具有焦点时,请点击某个按钮。
我使用asp:textbox和asp:button作为我的登录表单。
<$ c 创建一个全局变量,用于跟踪哪种表单处于焦点状态。 $ C><脚本> var currentForm = document.forms [0];< / script>
< form ...>< input onfocus =currentForm = this.form;/>< / form>
< form ...>< input onfocus =currentForm = this.form;/>< / form>
将一个键盘处理程序添加到窗口中,查找Enter键,然后在提交表单时提交表单这是重点:$ b
$ b pre $ 函数globalKeyPressed(event){
if(event.keyCode == ENTER){//这是伪代码,检查如何真正做到这一点
currentForm.submit();
}
}
I have a website with 2 forms. One for search and another for the login. When I use the enter key to submit, the search is always called because it is the first form on the page.
What I want to do is program the enter key to click a certain button when a certain textbox has focus.
I'm using asp:textbox and asp:button for my login form.
Create a global variable which tracks what form is in focus:
<script> var currentForm = document.forms[0];</script>
<form ...><input onfocus="currentForm = this.form;"/></form>
<form ...><input onfocus="currentForm = this.form;"/></form>
Attach a keyboard handler to the window, look for the Enter key, then when it's hit submit the form that's being focused:
function globalKeyPressed(event) {
if (event.keyCode == ENTER) { // This is pseudo-code, check how to really do it
currentForm.submit();
}
}
这篇关于在网站上输入多个表单的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!