简体   繁体   English

输入未清除字段时的 HTML 输入

[英]HTML Input on enter not clearing field

I've tried multiple scripts and approaches on clearing the input field once enter is hit.我已经尝试了多种脚本和方法来清除输入字段一旦被点击。 I had one script work although it was too fast so the message could never be submitted.我有一个脚本工作,虽然它太快了,所以永远无法提交消息。 I was wondering if there is any way I could delay it?我想知道有什么办法可以延迟吗?

This is the script I'm using although it submits too fast这是我正在使用的脚本,尽管它提交得太快了

 <input class="chat-window-message keydown" name="message" id="InputMessage" type="text" autocomplete="off" placeholder="....." onload="self.focus();" autofocus required /> <script> document.getElementById('InputMessage').addEventListener('change',function(){ //somehow search for the term here //remove text document.getElementById('InputMessage').value=''; },false); </script>

Write a function in JS called when you click on the submit button.在 JS 中编写一个函数,当您单击提交按钮时调用。 In this function, call submit() on the form, then clear the field (with your code or the reset() method).在此函数中,在表单上调用submit() ,然后清除该字段(使用您的代码或reset()方法)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM