我正在使用本教程(http://code.tutsplus.com/tutorials/real-time-messaging-for-meteor-with-meteor-streams--net-33409)制作与流星的聊天应用程序,如果您按下输入键提交您的评论,而不是每次按发送按键,我都会试图将其设置在其中。按Enter键提交评论?
以下是应用程序用于通过按发送按钮提交评论的JavaScript代码,但没有人知道我需要输入什么代码才能通过按Enter键提交评论?
// 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
});
});
我会在我的原始文章中的现有代码之后添加这个权限吗?我尝试过,但它不起作用。 – 5AMWE5T
@ user3330382不,你可以用你的代码代替你的代码。另外,如果你想跟随这个词的教程,你可能需要捕捉'textarea'上的'keyup'事件。 –
感谢这有助于 – 5AMWE5T