读书人

来看下这段代码哪里出错了很是头疼!

发布时间: 2012-03-02 14:40:28 作者: rapoo

大虾来看下这段代码哪里出错了,很是头疼!!!!!!!!!!!
<SCRIPT LANGUAGE= "JavaScript ">
function password() {
var testV = 1;
var pass1 = "1 "
while (testV < 3000) {
if (!pass1)
history.go(-1);
if (form1.text1.value==pass1) {
alert( '密码正确,准予进入 ')
window.location.href = "22.htm ";
break;
}

testV+=1;
var pass1 =
alert( '密码不正确,你没获得主人的批准。 ');
history.go(-1);
break;
}
if (pass1!= "password " & testV ==3)
history.go(-1);
return false;
}
document.write(password());
</SCRIPT>

请问以上代码哪里错了,输入正确密码后,没有跳转到相应页面

[解决办法]
请注意document.write 会重写页面的,

你可以这样

<input type=button value= '进入 ' onclick= "password() ">

[解决办法]
<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>
[解决办法]
呵呵,你是什么时候触发password()运行的,怎么能确保是在输入密码后运行。按你用document.write(password());有可能你还没输入密码,但是password()已经运行过了。

读书人网 >JavaScript

热点推荐