我正在尝试通过在文本区域中单击输入来发送表单。我正在尝试这个:
$('.chatMessage').on('keyup', function(e) {
if (e.which == 13 && ! e.shiftKey) {
$.ajax({
url: "/index.php",
type: "post",
data: $('form').serialize()
});
}
});
当我点击“输入”时,它会转到“如果”但未发送表单。
html:
<form id="form" method="POST" action="/index.php">
<textarea class="chatMessage" name="text" placeholder="Имя клиента"></textarea>
<br>
<input class="button" type="submit" name="enter" value="Отправить">
</form>
最佳答案
感谢大家!:) 我发现了一个问题。它在我代码的另一部分。一般来说,这对我有用:
$('.chatMessage').on('keyup', function(event) {
if (event.which == 13 && ! event.shiftKey) {
$(this).closest('form').submit();
}
关于javascript - 通过在文本区域中单击输入来发送表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37814989/