日期:2014-05-16  浏览次数:20338 次

问个弱弱的问题,关于光标定位
有两个文本框,第一个填新密码
第二个填确认密码
本意是填过新密码后不管点哪里,光标都会到定位到第二个文本框,即使点其他文本控件光标也是定位到确认密码文本框
我写了一个,但发现了问题,如下
-------------------------
<script   language= "javascript ">
function     check()
{
        var   txtpwdok=document.getElementById( "txtPwdOk ");
        alert( "aaaaaa ");//如果在这里加一个弹出框,那就会自动定位到确认密码框,如果没有,则光标不会定位到txtpwdok,而是消失
        txtpwdok.focus();
}
</script>
<html>
<body>
<input   type= "text "   id=txtPwd     onchange= "check(); "> <br>
<input   type= "text "   id=txtPwdOk   >
</body>
</html>
小弟我javascript只懂一些,请问有什么办法在新密码框改动完后点其他地方直接就让光标定位到下面的文本框??谢谢了

------解决方案--------------------
<html>
<body>
<script>
function ToPwdOk(){
document.onclick=function(){
document.getElementById( "txtPwdOk ").focus();
}
}
</script>
<input type= "text " id= "txtPwd " onblur= "ToPwdOk() "> <br>
<input type= "text " id= "txtPwdOk " >
</body>
</html>