我的表格重置但样式没有重置,
My form resets but not the styles,
当我关闭模式时,里面的表单会重置,但样式不会重置,如果密码不匹配,它会显示红色边框颜色,如果我关闭它,它会保持不变吗?
JAVASCRIPT
function checkForm(){
var nameRg = document.getElementById("nameRg").value;
var ok = true;
if (nameRg == "") {document.get.ElementById("nameRg").style.borderColor="#ff2020";
ok = false;}
return ok;
};
$(.modal).on('hidden.bs.modal', function(){
$(this).find('form')[0].reset();
});
HTML
<form action="post" onsubmit="return checkForm()">
<div class="form-group register-group register-name-group">
<label for="name">Name :</label>
<input id="nameRg" type="text" class="form-control" name="name" placeholder="eg. Leutrim Osmani">
</div>
</form>
reset()
方法仅重置表单的输入值。您将必须手动重置样式。所以在你的模态关闭事件函数中,你必须有这样一行来将边框颜色重置为默认值:
document.getElementById("nameRg").style.borderColor = "#ff2020";
当我关闭模式时,里面的表单会重置,但样式不会重置,如果密码不匹配,它会显示红色边框颜色,如果我关闭它,它会保持不变吗?
JAVASCRIPT
function checkForm(){
var nameRg = document.getElementById("nameRg").value;
var ok = true;
if (nameRg == "") {document.get.ElementById("nameRg").style.borderColor="#ff2020";
ok = false;}
return ok;
};
$(.modal).on('hidden.bs.modal', function(){
$(this).find('form')[0].reset();
});
HTML
<form action="post" onsubmit="return checkForm()">
<div class="form-group register-group register-name-group">
<label for="name">Name :</label>
<input id="nameRg" type="text" class="form-control" name="name" placeholder="eg. Leutrim Osmani">
</div>
</form>
reset()
方法仅重置表单的输入值。您将必须手动重置样式。所以在你的模态关闭事件函数中,你必须有这样一行来将边框颜色重置为默认值:
document.getElementById("nameRg").style.borderColor = "#ff2020";