为什么单击提交按钮后无法清除数据?

问题描述 投票:0回答:2

我很简单:

我现在使用google form作为数据库。

在向提交按钮添加了重置功能之后,它再次将我发送到google表单的响应页面的JS文件。

您能帮忙吗?谢谢

<form id="form" action="https://docs.google.com/forms/u/2/d/e/1FAIpQLSeBJHw1Q6YlwO_0s2OgMhuyQEj4PLvToM1N1G5BEYQRiZlCLQ/formResponse">
                <label for="">It's FREE</label>
                <input type="text" placeholder="Full Name" class="inputs" id="input1" name="entry.1045366435">
                <input type="email" placeholder="Email" class="inputs" id="input2" name="entry.1398681060">
                <textarea cols="30" rows="10" placeholder="Message" id="input3" name="entry.403219718"></textarea>
                <input type="submit" id="submit" value="Send">
            </form>
$('#form').submit(function(e) {
    alert("Thanks for signing up. We will contact you as soon as we can.");
    e.preventDefault();
    $.ajax({
        url: "https://docs.google.com/forms/u/2/d/e/1FAIpQLSeBJHw1Q6YlwO_0s2OgMhuyQEj4PLvToM1N1G5BEYQRiZlCLQ/formResponse",
        data: $(this).serialize(),
        type: "POST",
        dataType: "xml",
        success: function(data) {
            console.log('Submission successful');
        },
        error: function(xhr, status, error) {
            console.log('Submission failed: ' + error);
        }
    });
});
//Alert + Disable google form response page

document.getElementById("submit").onclick = function() {
    document.getElementById("input1").reset();
    document.getElementById("input2").reset();
    document.getElementById("input3").reset();
 }​
javascript google-drive-api google-form
2个回答
1
投票

首先,您不应有两个不同的提交处理程序,只需使用一个。第二次重置在表格上,而不是输入上。

success: function(data) {
  $('#form')[0].reset()
  console.log('Submission successful');
},

0
投票

reset()是一种针对表单的方法。

因此您将需要选择表格。

document.getElementById("form").reset();
© www.soinside.com 2019 - 2024. All rights reserved.