【发布时间】:2014-03-20 18:16:44
【问题描述】:
我正在根据本教程 (http://code.tutsplus.com/tutorials/real-time-messaging-for-meteor-with-meteor-streams--net-33409) 开发一个使用 Meteor 构建的聊天应用程序,并且我正在尝试让它在您按下 Enter 时提交您的消息,而不必按下发送按钮。
以下是应用程序用于通过按“发送”按钮提交评论的 javascript 代码,但有人知道如何添加回车功能吗?
// when Send Chat clicked add the message to the collection
Template.chatBox.events({
"click #send": function() {
var message = $('#chat-message').val();
chatCollection.insert({
userId: 'me',
message: message
});
$('#chat-message').val('');
//add the message to the stream
chatStream.emit('chat', message);
}
});
chatStream.on('chat', function(message) {
chatCollection.insert({
userId: this.userId,
subscriptionId: this.subscriptionId,
message: message
});
});
【问题讨论】:
标签: javascript jquery submit chat enter