javascript - 如何在不刷新页面的情况下重置输入值
问题描述
我想在单击发布按钮后重置输入值而不刷新页面
以下代码在while循环中
<input class="comment" type="text" placeholder="Write comment"><button class="comment_post" onClick="reset()">Post</button>
我用过
function reset(){
document.getElementsByClassName('comment').value=null;
}
<input class="comment" type="text" placeholder="Write comment"><button class="comment_post" onClick="reset()">Post</button>
请提供代码
解决方案
不使用 jQuery 文件包含,您可以简单地使用以下函数。
function reset()
{
document.getElementsByClassName('comment')[0].value='';
}
<input class="comment" type="text" placeholder="Write comment">
<br><br>
<button class="comment_post" onClick="reset()">Post</button>
推荐阅读
- postgresql - Postgres in-filter complexity
- django - 如何在将文件保存到 django rest_framework 中的数据库之前重命名文件
- r - 使用存储在列表中的数据帧内的 table() 创建新的数据帧
- javascript - 用 Javascript 编译 Latex
- html - 淘汰赛 JS 复选框列表不绑定
- php - 逐张从excel文件中提取数据。单工lsx
- c - Different ways of suppressing 'uninitialized variable warnings' in C
- c++ - Why is a member in a primary class template not declared in the scope of the specialized class?
- docker - Docker compose:需要一个映射或映射列表以进行合并,但找到了标量
- javascript - 防止android webview中的无效输入值更改