说明:在填写表数据时当输入完一个文本框后,输入下一个文本框时需要用Tab键切换,但是有的人喜欢用Enter键切换下一个,此方法是Enter取代Tab键。
效果:
注释:键盘Enter键数字为:13
键盘Tab键数字为:9
函数代码:
1 private void SetEnt() 2 { 3 foreach (Control txt in (this.Page.Form.FindControl("ContentPlaceHolderEntity")).Controls) 4 { 5 if (txt is System.Web.UI.WebControls.TextBox) 6 { 7 if (((TextBox)txt).CssClass != "erp_textarea") 8 ((TextBox)txt).Attributes.Add("onkeydown", "if (window.event.keyCode==13) window.event.keyCode=9"); 9 } 10 if (txt is System.Web.UI.WebControls.DropDownList) 11 { 12 ((DropDownList)txt).Attributes.Add("onkeydown", "if (window.event.keyCode==13) window.event.keyCode=9"); 13 } 14 if (txt is System.Web.UI.WebControls.CheckBox) 15 { 16 ((CheckBox)txt).Attributes.Add("onkeydown", "if (window.event.keyCode==13) window.event.keyCode=9"); 17 } 18 } 19 }