提交后如何清空表格栏位?

时间:2019-06-02 13:58:48

标签: reactjs

单击按钮“获取天气”之后,如何清空“城市” 字段?并且我必须单击两次按钮以获得正确的“时间” image

代码链接: project link

4 个答案:

答案 0 :(得分:1)

document.getElementById("city").value = ""

---如果它是输入字段或文本区域,则将起作用。

答案 1 :(得分:0)

您只需编写"name_of_object".setText(" ");

答案 2 :(得分:0)

看看这个:

<!DOCTYPE html>
<html>
<body>
 
<p>Enter some text in the fields below,
then press the "Reset form" button to 
reset the form.</p>
 
<form id="myForm">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br><br>
  <input type="button" onclick="submit()" value="Reset form">
</form>
 
<script>
function submit() {
  /*Put all the data posting code here*/
 document.getElementById("myForm").reset();
}
</script>
 
</body>
</html>

答案 3 :(得分:0)

getWeather = async (e) => {
  e.preventDefault();
  // const city = e.target.elements.city.value;
  const element = e.target.elements.city;
  const city = element.value;

  // after data fetching or at once
  element.value="";

还请阅读有关uncontrolled components的文档。