紧急求助js的焦点问题,请各位帮忙
项目中的画面,文本框输入一定字符之后自动将焦点设到下一项(已通过onkeyup事件和focus方法实现),另外输入结束之后检查是否正确(已通过onblur事件实现)。目前现象是,检查输入不正确后,先弹出的消息,之后才将该项用红色标记;如何才能实现先标红,后弹消息呢?(推测是focus改变焦点产生的影响)
请各位一定帮帮忙啊
代码如下:
<html>
<head>
<title> Untitled </title>
<script language= "javascript ">
function nextFocus(obj){
if(obj.value.length > = obj.maxLength){
document.form1.txt2.focus();
}
}
function check(obj){
if(obj.value!= "000000 "){
obj.style.backgroundColor= "#FF0000 ";
alert( "Error! ");
}
}
</script>
</head>
<body>
<form name= "form1 ">
<input type= "text " name= "txt1 " maxlength= "6 " onkeyup= "nextFocus(this) " onblur= "check(this) ">
<input type= "text " name= "txt2 ">
</form>
</body>
</html>
------解决方案--------------------function check(obj){
if(obj.value!= "000000 "){
obj.focus();
obj.style.backgroundColor= "#FF0000 ";
alert( "Error! ");
}
}
------解决方案-------------------- <html>
<head>
<title> Untitled </title>
<script language= "javascript ">
var checked = false;
function nextFocus(obj){
if(obj.value.length > = obj.maxLength){
check(obj);
document.form1.txt2.focus();
}
}
function check(obj){
if(obj.value!= "000000 "){
obj.style.backgroundColor= "#FF0000 ";
if(event.type== "blur ") alert( "Error! ");
}
}
</script>
</head>
<body>
<form name= "form1 ">
<input type= "text " name= "txt1 " maxlength= "6 " onkeyup= "nextFocus(this) " onblur= "check(this) ">
<input type= "text " name= "txt2 ">
</form>
</body>
</html>