清除表单而不刷新

kar*_*eth 0 php jquery

我正在使用一个具有recaptcha的表单并使用jquery进行验证,一切都运行良好*信息发送到我的电子邮件,所有必填字段在发送之前进行检查)

我面临的唯一一个问题是,一旦信息被发送并且所有字段都被重置,错误消息只有在被隐藏的情况下才是可见的,如果页面是我改变了js"reset"instated of"clear"但这刷新了pagge谢谢你的消息不再可见了.

(我知道也许所有听起来有点令人困惑)这就是正在谈论的代码

function validateCaptcha(){
    challengeField = $("input#recaptcha_challenge_field").val();
    responseField = $("input#recaptcha_response_field").val();
    nameField = $("input#name").val();
    emailField = $("input#email").val();
    phoneField =$("input#phone").val();
    reasonField =$("input#reason").val();
    messageField =$("textarea#message").val();

    var html = $.ajax({
    type: "POST",
    url: "ajax.recaptcha.php",
    data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField +"&name="+ nameField +"&email=" + emailField +"&phone="+ phoneField + "&reason=" + reasonField +"&message=" + messageField,
    async: false
    }).responseText;

    if(html == "success")
    {
        $('#contactForm').each (function(){
          this.reset();
         Recaptcha.reload();
        }) 

        $("#thanks").html("Thank you");


         return false;
    }

    else
    {
        $("#captchaStatus").html("Your captcha is incorrect. Please try again");
        Recaptcha.reload();
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

Sha*_*oli 7

使用重置按钮清除表单字段.

<input type="reset" />
Run Code Online (Sandbox Code Playgroud)