[英]keypress doesn't work in function i made for some chat application
I have some problem with key press when calling the key press in my function it does not work at all even I use multiple solution for it so I try to call a difference method key up or key down but it also not work 我在函数中调用按键时遇到按键问题,即使我使用了多种解决方案,按键也根本不起作用,因此我尝试调用差异方法按键向上或向下按键,但它也无法正常工作
chat.connection.start().done(function () {
var connectionname = prompt();
chat.server.setConnectionName(connectionname);
$("#myConnectionName").val(connectionname);
$("inmessage").keypress(function (e) {
if (e.which == 13) {
var partnerId = $(this).closest('#chatBox').find('#partnerConnectionId').val();
var message = $(this).val();
chat.server.send(partnerId, message);
$(this).val('');
}
});
)
It show no error method but it does not work also for other keydown. 它没有显示任何错误方法,但是对于其他按键也不起作用。
As @briosheje mentioned in comments you need to use a class or id selector : 正如@briosheje在评论中提到的,您需要使用类或id选择器:
chat.connection.start().done(function () {
var connectionname = prompt();
chat.server.setConnectionName(connectionname);
$("#myConnectionName").val(connectionname);
$(".inmessage").keypress(function (e) {
if (e.which == 13) {
var partnerId = $(this).closest('#chatBox').find('#partnerConnectionId').val();
var message = $(this).val();
chat.server.send(partnerId, message);
$(this).val('');
}
});
)
var connectionname = prompt();
chat.server.setConnectionName(connectionname);
$("#myConnectionName").val(connectionname);
$(".inmessage" **or** "#inmessage").keypress(function (e) {
if (e.which == 13) {
var partnerId = $(this).closest('#chatBox').find('#partnerConnectionId').val();
var message = $(this).val();
chat.server.send(partnerId, message);
$(this).val('');
}
});
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.