C#回车切换焦点为了让用户有更好的输入体念,往往要在很多小地方加已修饰.如让用户更快捷的方便的录入表单.因此在网页中加入回车切换焦点和回车提交表单是很重要的.
C#回车切换焦点之Javascript代码:
﹤script language="javascript" type="text/javascript"﹥
//设置焦点
functionSetFocus(TextBoxID)
{
if(event.keyCode==13)
{
if(TextBoxID!=null)
{
vartxtCtrl=document.getElementById (TextBoxID);
txtCtrl.focus();
window.event.keyCode=0;
}
}
}
//提交
function Submit(ButtonID)
{
if(event.keyCode==13)
{
if(ButtonID!=null)
{
var BtnCtrl =document.getElementById (ButtonID);
BtnCtrl.click();
}
window.event.keyCode=0;
}
}
﹤/script﹥
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
C#回车切换焦点之Page Load事件中注册属性:
txtUser.Attributes.Add("onkeypress", "SetFocus('txtPswd');");
txtPswd.Attributes.Add("onkeypress", "Submit('btnLogin');");
- 1.
- 2.
- 3.
为用户名注册onkeypress事件,在事件中切换焦点到txtPswd密码输入筐,为密码输入筐也注册onkeypress事件,在事件中提交表单
C#回车切换焦点的基本内容就向你介绍到这里,希望那个对你了解和学习C#回车切换焦点有所帮助。
【编辑推荐】