我正在使用以下代码...
if (theForm.textOne.value.trim() == "" || theForm.textTwo.value.trim() == "")
{
alert("part of the form is blank");
document.getElementById("textTwo").style.borderColor="red";
}
问题是当警报消失时红色消失。如何使边框保持该颜色?
最佳答案
为了显示边框,您需要的不仅仅是边框颜色来显示:您还需要边框样式和边框宽度
它还存在库来帮助您操作 html 文档
看看这个 JQuery 的优点:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(function(){
$("form").submit(function() {
var valid = true;
$("form #textTwo, form #textOne").each(function(){
if ($(this).val().trim() == "")
{
$(this).css("border","1px #ff0000 solid");
valid = false;
}
});
if(!valid){
alert("part of the form is blank");
return false;
}
});
})
</script>
要了解更多:http://jquery.com/
关于javascript - 使用javascript边框颜色消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12466288/