按回车刷新页面

Refresh page when press enter

我的代码很少 <asp:ImageButton> 。但是我想当我按下 Enter 键时,其他人不会改变,只有 submit 按钮有效。现在,当我在我的代码中按 Enter 键时,.calendar class 按钮工作并且日历出来。

jquery

$('form').keypress(function (e) {
            if (e.which == 13) {
                $('.submit').submit();
                //return false;
            }
        });

.aspx

<div id="form">
<div id="main">
    <div>
        <ul>
            <li>
                <asp:TextBox ID="txtDate1" runat="server" CssClass="textbox"></asp:TextBox>
                <asp:ImageButton ID="Button1" CssClass="calbutton" runat="server" OnClick="Button1_Click" Text="Show Calendar" AutoPostBack="True"/>
                <div class="calendar">
                    <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Visible="False">
                    </asp:Calendar>
                </div>
            </li>
            <li>
                <asp:ImageButton ID="ImageView" CssClass="submit" runat="server" onclick="ImageView_Click"  AutoPostBack="True" />
            </li>
        </ul>
    </div>

包裹在 asp:panel 中并设置默认按钮。

像这样的东西可能对你朋友有用..:)

HTML

<form id="myForm">
        <div id="main">
            <div>
                <ul>
                    <li>
                        <asp:TextBox ID="txtDate1" runat="server" CssClass="textbox"></asp:TextBox>
                        <asp:ImageButton ID="Button1" CssClass="calbutton" runat="server" OnClick="Button1_Click" Text="Show Calendar" AutoPostBack="True" />
                        <div class="calendar">
                            <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Visible="False"></asp:Calendar>
                        </div>
                    </li>
                    <li>
                        <asp:ImageButton ID="ImageView" CssClass="submit" runat="server" onclick="ImageView_Click" AutoPostBack="True" />
                    </li>
                </ul>
            </div>
        </div>
    </form>

脚本

$('#myForm input').keypress(function (e) {
            if (e.which == 13) {
                $("#myForm").submit();
                return false;
            }
        });