当我关闭模态时,里面的表单会重置而不是样式,如果密码不匹配则会得到红色边框颜色,如果我关闭它仍然保持不变?
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>
答案 0 :(得分:0)
reset()
方法仅重置表单的输入值。您必须手动重置样式。因此,在你的模态关闭事件函数中,你必须有这样的一行来将边框颜色重置为默认值:
document.getElementById("nameRg").style.borderColor = "#ff2020";