Javascript 不会在按下回车键时提交,它只是清除文本框

标签 javascript html

我有以下代码:

    <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/

相关文章:

html - 删除 HTML/CSS 横幅上的空白?

html - XPath 搜索多个嵌套元素

javascript - 计算货币

javascript - 在重新排列 polymer 元素中的子跨度时如何通过 wct 测试?

javascript - 在 html 中显示 RTSP 流

javascript - 澄清一些关于 moment.js 的疑虑

javascript - instanceof 在 JSON.stringify() 中的行为有何不同?

javascript - 属性或方法 "value"未在 vue js 2 嵌套组件中的实例上定义

javascript - Angular 递归方法不返回值

html - 我的模板响应式菜单 Bootstrap 不起作用?