简体   繁体   English

无法清除文本输入字段

[英]Cannot clear text input field

I've tried several different ways, including Pure-JS and jQuery, but I can't get my input text field to clear. 我尝试了几种不同的方法,包括Pure-JS和jQuery,但无法清除输入文本字段。 Please help. 请帮忙。

Here's the relevant HTML: 以下是相关的HTML:

<div align="center" id="searchDiv"></div>
<input type="text" id="searchBar" size="40" onsubmit="loadAllItems()">
<input type="submit" id="searchButton" value="Search" onclick="loadAllItems()">
<input type="button" value="Reset" onclick="reset()">

I'm trying to submit the searchBar, run backend code, and then call the reset() function to avoid manually clearing the text field: 我正在尝试提交searchBar,运行后端代码,然后调用reset()函数以避免手动清除文本字段:

function reset() {
        document.getElementById("gradeQuestionsForm").reset();
        document.getElementById('Output1').innerHTML = '';
        document.getElementById('Output1').innerHTML = '';
        updateStatus('Form has been reset.');
      }

I tested with a JSFiddle . 我用JSFiddle进行了测试 Please advise. 请指教。

With jQuery you can do like this 使用jQuery,您可以这样做
fiddle 小提琴

$('#searchBar').val('');

Try document.getElementById("searchBar").value = ''; 试试document.getElementById("searchBar").value = '';

Also, you need to set LOAD TYPE TO No wrap -in <head> in your JSFiddle 另外,您需要在JSFiddle中将LOAD TYPE设置为No wrap -in <head>

在此处输入图片说明 .

See more on running script on JSFiddle here . 此处查看有关在JSFiddle上运行脚本的更多信息

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

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