我正在尝试在提交表单后清除输入字段,但它只是明文,但我需要边框,而且某些属性也是
//验证名称
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(){
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;
});
答案 0 :(得分:0)
我不确定你在尝试什么。表单提交后,表单已经重置。当您使用ajax时,它会保留其值。在这种情况下试试这个:
$('#form_id')[0].reset();
答案 1 :(得分:0)
为form
提供document.getElementById("formId").reset();
并使用此
{{1}}