我是 PHP、SQL 和 JQUERY/JS 的新手。我试图做到的是,当一个人按下回车键(在输入字段中)时,会发生同样的事情,就像他们点击现有按钮一样。
这是原始按钮代码:
$(document).on("click", '.submit', function(event) {
var to_user_id = $(this).attr('id');
to_user_id = to_user_id.replace(/chatButton/g, "");
sendMessage(to_user_id);
});
我尝试让 Enter 做与上面代码相同的事情:
$('#chatMessage3').keyup(function(e) {
if (e.keyCode == 13) {
var to_user_id = $(this).attr('id');
sendMessage(to_user_id);
}
最佳答案
您的提交按钮似乎具有 chatButton1
、chatButton2
等 ID,而您只想发送 1
、 2.
.您需要在 #chatMessage3
处理程序中执行类似的替换:
$('#chatMessage3').keyup(function(e) {
if (e.keyCode == 13) {
var to_user_id = $(this).attr('id');
to_user_id = to_user_id.replace(/chatMessage/, '');
sendMessage(to_user_id);
}
关于javascript - 如何保存函数的输入值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55607938/