Refresh page when press enter

旧时模样 提交于 2019-12-13 17:17:13

问题


My code has few <asp:ImageButton> . But I want to make when I press Enter key, not others change but only submit button works . Now, when I press Enter key in my code , .calendar class button works and calendar come out.

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>

回答1:


Something like this might work for u mate.. :)

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>

Script

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



回答2:


Wrap in asp:panel and set defaultbutton.



来源:https://stackoverflow.com/questions/28229533/refresh-page-when-press-enter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!