简体   繁体   English

提交表单后清除输入字段

[英]clear input fields after submit form

I'm trying to clear input fields after I submit a form but it only clear text but i need that border and some attributes will be too 提交表单后,我试图清除输入字段,但只能清除文本,但我需要边框,某些属性也是如此

//validation name //验证名称

document.questionform.name.onchange= function() {
            var name = document.questionform.name.value;
            if (name === "") {
                document.questionform.name.removeAttribute("class", "ready");
                document.questionform.name.style.border = "1px solid #da3637";
                document.getElementById("questionError").style.display = "block";
                document.getElementById("questionErrorTwo").style.display = "none";
            } else {
                    document.questionform.name.style.border = "1px solid #509d12";
                    document.getElementById("questionError").style.display = "none";
                    var pattern = new RegExp("^[а-я]+$", "i");
                    var isValid = this.value.search(pattern) >= 0;
                    if (!(isValid)) {
                        document.questionform.name.style.border = "1px solid #da3637";
                        document.getElementById("questionErrorTwo").style.display = "block";
                        document.questionform.name.removeAttribute("class", "ready");
                    } else {
                        document.getElementById("questionErrorTwo").style.display = "none";
                        document.questionform.name.style.border = "1px solid #509d12";
                        document.questionform.name.setAttribute("class", "ready");
                    }
            }
        };

Ajax: $("#questionsave").click(function() { Ajax:$(“#questionsave”)。click(function(){

    var url = "questionForm.php"; 

    $.ajax({
           type: "POST",
           url: url,
           data: $("#questform").serialize(), 
           success: function(data)
           {
                var name = $('input[name=name]').val("");
                var tel = $('input[name=phone]').val("");
                document.questionform.phone.removeAttribute("class", "ready");
                document.questionform.name.removeAttribute("class", "ready");
                document.getElementById("questionsave").setAttribute("disabled");
                document.getElementById("questionsave").style.cursor = "not-allowed";
                document.getElementById("questionsave").style.opacity = "0.8";
                document.questionform.name.style.borderColor = "#e4e4e6";
                document.questionform.phone.style.borderColor = "#e4e4e6";
           }
         });

    return false; 
    });

I am not sure what you are trying. 我不确定您要尝试什么。 After form submit the form is already reset. 提交表单后,表单已被重置。 It retains its value when you are using ajax. 使用ajax时,它保留其值。 In that case try this: 在这种情况下,请尝试以下操作:

$('#form_id')[0].reset();

输入form id并使用它,

document.getElementById("formId").reset();

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

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