可能重复:
防止使用回车键提交表单
在我的项目中,我试图禁用该Enter键并提供我自己的输入键功能。(我还没有做过)
下面的功能正在工作,但是每当我Enter在字段内按下键时TextBox
,内容就会添加到div
(根据需要)并且在TextBox
字段中,输入键功能正在发生(我不想要)。如何停止输入键功能在TextBox
字段上运行?为了清楚地理解,请参阅我在下面代码中的评论。
.aspx 文件(工作)
<asp:TextBox ID="msg" BackColor="Transparent" runat="server" BorderStyle="None"
TextMode="MultiLine" />
jQuery(工作)
$('#msg').keypress(function (e) {
if (e.which == 13) {
//Shows the TextBox text in a Div, which I want to.
chat.server.send($('#msg').val()); //also going one step down in TextBox field which I dont want to.
$('#msg').val(''); //Clearing the Text in TextBox field
//what should I add here to make the Enter Key work only for the DIV?
}
});