Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript js提交后清除HTML表单_Javascript_Html_Json_Forms - Fatal编程技术网

使用Javascript js提交后清除HTML表单

使用Javascript js提交后清除HTML表单,javascript,html,json,forms,Javascript,Html,Json,Forms,我查看了其他线程,但找不到解决方案,但我有一个表单可以正确地提交到Google工作表,但按submit后输入内容仍保留 代码如下: <form name="rvcasole-formresponses"> <p class="text name">FIRST NAME</p> <input type="text" name="firstName" class="_input firstName"> <p class="text

我查看了其他线程,但找不到解决方案,但我有一个表单可以正确地提交到Google工作表,但按submit后输入内容仍保留

代码如下:

<form name="rvcasole-formresponses">

  <p class="text name">FIRST NAME</p>
  <input type="text" name="firstName" class="_input firstName">

  <p class="text name">LAST NAME</p>
    <input type="text" name="lastName" class="_input lastName">

  <p class="text email">EMAIL</p>
    <input type="text" name="email" class="_input email">

  <p class="text phone">PHONE</p>
    <input type="text" name="phone" class="_input phone">

  <button type="submit" class="button">SUBMIT</button>
</form>

<script>  
  const scriptURL = 'https://script.google.com/macros/s/AKfycbydQrV11QKRWOJ-HPTlEsVaZa1Z3z15DAN6It5k42b8voWDO4w/exec';
  const form = document.forms['rvcasole-formresponses'];
  form.addEventListener('submit', e => {  
   e.preventDefault();
   fetch(scriptURL, { method: 'POST', body: new FormData(form)})  
    .then(response => console.log('Success!', response))  
    .catch(error => console.error('Error!', error.message));
  })  
 </script>  

名字

姓氏

电子邮件

电话

提交 常量脚本URL=https://script.google.com/macros/s/AKfycbydQrV11QKRWOJ-HPTlEsVaZa1Z3z15DAN6It5k42b8voWDO4w/exec'; const form=document.forms['rvcasole-formresponses']; form.addEventListener('submit',e=>{ e、 预防默认值(); fetch(scriptURL,{method:'POST',body:newformdata(form)}) .then(response=>console.log('Success!',response)) .catch(error=>console.error('error!',error.message)); })
只需添加以下内容:

添加表单:id=“myForm”


名字

姓氏

电子邮件

电话

提交 常量脚本URL=https://script.google.com/macros/s/AKfycbydQrV11QKRWOJ-HPTlEsVaZa1Z3z15DAN6It5k42b8voWDO4w/exec' const form=document.forms['rvcasole-formresponses'] form.addEventListener('submit',e=>{ e、 预防默认值() 获取(脚本URL{ 方法:“POST”, 正文:新表单数据(表单) }) .然后(功能(响应){ var frm=document.getElementsByName('rvcasole-formresponses')[0]; frm.reset(); console.log('Success!',response); }) .catch(error=>console.error('error!',error.message)) })
我们可以使用
document.getElementById('formresponses').reset()重置表单。

const scriptURL='1〕https://script.google.com/macros/s/AKfycbydQrV11QKRWOJ-HPTlEsVaZa1Z3z15DAN6It5k42b8voWDO4w/exec'  
const form=document.forms['rvcasole-formresponses']
form.addEventListener('submit',e=>{
e、 预防默认值()
fetch(scriptURL,{method:'POST',body:newformdata(form)})
.then(response=>document.getElementById('formresponses').reset())
.catch(error=>console.error('error!',error.message))
})

名字

姓氏

电子邮件

电话

提交
欢迎来到SO。我没有看到任何试图擦除字段值的尝试。。。
        document.getElementById("myForm").reset();