点击textbox对应到button点击Enter

功能实现:光标所在的位置(TextBox),直接点击键盘Enter后,可以定位到指定的Button,执行Click事件。

 

//首先写JS方法在开头调用

<head runat="server">

    <title>OfficeSearch</title>

    <link href="site.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">

        function SubmitKeyClick(button) {

            if (event.keyCode == 13) {

                event.keyCode = 9;

                event.returnValue = false;

                document.all[button].click();

            }

        }

    </script>

</head>

 

//按钮位置布局

<td align="center">

                Office2016TagNo:<asp:TextBox ID="txtTagno16" runat="server"></asp:TextBox>

                LIC:<asp:TextBox ID="txtLic16" runat="server"></asp:TextBox>

                Outlook: <asp:TextBox ID="txtOutlook16" runat="server"></asp:TextBox>

          <asp:Button ID="btOff16" runat="server" Text="Office2016" />

</td>

 

//最后在加载页面的时候写如下方法

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.GridView1.Attributes("bordercolor") = System.Drawing.ColorTranslator.ToHtml(Drawing.Color.Gray)

        Me.gvOff2016.Attributes("bordercolor") = System.Drawing.ColorTranslator.ToHtml(Drawing.Color.Gray)

 

        Me.TBTagno.Attributes.Add("onkeydown", "SubmitKeyClick('Button1')")

        Me.TBLic.Attributes.Add("onkeydown", "SubmitKeyClick('Button1')")

        Me.TBVersion.Attributes.Add("onkeydown", "SubmitKeyClick('Button1')")

 

        Me.txtTagno16.Attributes.Add("onkeydown", "SubmitKeyClick('btOff16')")

        Me.txtLic16.Attributes.Add("onkeydown", "SubmitKeyClick('btOff16')")

        Me.txtOutlook16.Attributes.Add("onkeydown", "SubmitKeyClick('btOff16')")

End Sub

posted @ 2016-03-10 17:52  iDennis  阅读(81)  评论(0)    收藏  举报