请注意document.write 会重写页面的,你可以这样<input type=button value='进入' onclick="password()">

解决方案 »

  1.   

    <form name="form1">
    <input type="text" name="test" onblur="password()">
    </form>
    <SCRIPT LANGUAGE="JavaScript">
    function password() {
    if (form1.test.value=="1111") {
    alert('密码正确,准予进入')
    window.location.href = "22.htm";
    } else{
    alert('密码不正确,你没获得主人的批准。');
    history.go(-1);
    }
    }
    </SCRIPT>
      

  2.   

    呵呵,你是什么时候触发password()运行的,怎么能确保是在输入密码后运行。按你用document.write(password());有可能你还没输入密码,但是password()已经运行过了。