我有以下代码:
<form style="position: absolute; bottom: 5px; padding-bottom: 10px;height: 10%;" id="newmessageForm">
<textarea name="message" placeholder="Type your message here" rows="9" cols="225" id="newmessage" resize="none" style="float: left; opacity: 0.7;"></textarea>
<input class="btn-login" type="Submit" name="send" style="float: left">
</form>
<script>
var chatInput = document.getElementById('newmessage');
var chatForm = document.getElementById('newmessageForm');
chatInput.onkeypress = function(e) {
if (e.charCode == 13) {
e.preventDefault();
chatForm.submit();
}
};
</script>
并且不是在按下回车键时发送消息,而是清除文本框,有人可以帮忙吗?
最佳答案
这个提交到哪里了? form 元素中没有action 属性。您将需要方法和操作属性才能使提交正常工作。
关于Javascript 不会在按下回车键时提交,它只是清除文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43032235/