问题
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