[英]clear input fields after submit form
提交表單后,我試圖清除輸入字段,但只能清除文本,但我需要邊框,某些屬性也是如此
//驗證名稱
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;
});
我不確定您要嘗試什么。 提交表單后,表單已被重置。 使用ajax時,它保留其值。 在這種情況下,請嘗試以下操作:
$('#form_id')[0].reset();
輸入form
id
並使用它,
document.getElementById("formId").reset();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.