function check(obj){
if(obj.value!="000000"){
                  obj.focus();
obj.style.backgroundColor="#FF0000";
alert("Error!");
}
}

解决方案 »

  1.   

    <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>
      

  2.   

    谢谢这么快就回复了。但是不好意思,刚才例子有点问题,实际是confirm对话框,如果点“OK”,就把焦点设回刚才check的控件;点“Cancle”就什么也不做(此时焦点和操作有关)。所以以上的方法就不好用了。
    function check(obj){
    if(obj.value!="000000"){
    obj.style.backgroundColor="#FF0000";
    if(confirm("Edit it?")){
    obj.focus();
    }
    }
    }
      

  3.   

    刚看到hookee() 的方法,谢谢,已经解决