C#回車切換焦點(diǎn)實(shí)例淺談
C#回車切換焦點(diǎn)為了讓用戶有更好的輸入體念,往往要在很多小地方加已修飾.如讓用戶更快捷的方便的錄入表單.因此在網(wǎng)頁中加入回車切換焦點(diǎn)和回車提交表單是很重要的.
C#回車切換焦點(diǎn)之Javascript代碼:
- ﹤script language="javascript" type="text/javascript"﹥
- //設(shè)置焦點(diǎn)
- 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﹥
C#回車切換焦點(diǎn)之Page Load事件中注冊(cè)屬性:
- txtUser.Attributes.Add("onkeypress", "SetFocus('txtPswd');");
- txtPswd.Attributes.Add("onkeypress", "Submit('btnLogin');");
為用戶名注冊(cè)onkeypress事件,在事件中切換焦點(diǎn)到txtPswd密碼輸入筐,為密碼輸入筐也注冊(cè)onkeypress事件,在事件中提交表單
C#回車切換焦點(diǎn)的基本內(nèi)容就向你介紹到這里,希望那個(gè)對(duì)你了解和學(xué)習(xí)C#回車切換焦點(diǎn)有所幫助。
【編輯推薦】