编码:
$(window).keypress(function (e) {
if (e.which == 13 || e.KeyCode == 13 || e.charCode == 13) { $("#<%=Send_btn.ClientID %>").trigger("click"); }
});
<asp:Button ID="Send_btn" runat="server" Text="Send" OnClick="Send_msg_Click"></asp:Button>
C#:
protected void Send_msg_Click(object sender, EventArgs e)
{
int ToClient = int.Parse(Request["frid"].ToString());
int FromClient = int.Parse(Request["uid"].ToString());
SendChatMessage(Message_txt.Text, ToClient, false);
ConversationDIv.InnerHtml = GetChat(ToClient, FromClient, Session["history"].ToString());
Message_txt.Focus();
Message_txt.Text = "";
var sc = "ScrollCoversationDiv('" + ToClient + "')";
ScriptManager.RegisterStartupScript(this, GetType(), "MyScript", sc, true);
}
当我点击输入时,Send_msg_click 在谷歌浏览器中被调用了两次,为什么?