贴上源码:<?
include "date.php" ;
include "conn.php" ;
$query="Select * From infolist";
$result=mysql_query("$query",$connection) or die (浏览失败!);
$row=mysql_fetch_array($result);
$password2=$row[PassWord];
?>
<HTML><STYLE>.chrome-seo_meta-nofollow,.chrome-seo_meta-nofollow *{outline:2px dashed #ffb400!important;outline-offset:1px;}.chrome-seo_nofollow,.chrome-seo_nofollow *{outline:2px dotted #e90000!important;outline-offset:1px;}</STYLE><STYLE>#shadowMeasureIt{display:none;position:fixed;width:100%;height:100%;top:0px;left:0px;opacity:0.4;background-color: #FFFFFF;z-Index:200000;cursor:crosshair}
#divCoordMeasureIt{display:none;position:absolute;z-Index:200001;top:0px;left:0px;opacity:1;background-color: #FFFFFF;text-align:left;color:#000000;font-family: arial;font-size: 11px;letter-spacing:1;font-weight: bold;border: 1px solid;border-color: #C0210B;padding:3px}
#divRectangleBGMeasureIt{width:100%;height:100%;opacity:0.2;background-color: #2D86DE;z-Index:199999;cursor:move}
#divRectangleMeasureIt{display:none;border: 1px #000000 solid;position:absolute;z-Index:199999;cursor:move}
#smallTextMeasureIt{color:#000000;font-family: arial;font-size: 7px;letter-spacing:1;font-weight: bold}</STYLE>
<HEAD><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><script language="javascript">
function check()

   if (document.form.password.value == 0)
   { 
     alert("请输入密码"); 
      document.form.password.focus();
          return (false);     
   } 
    if (document.form.password.value != <? echo $password2 ?>)
              { 
                alert("密码错误请重新输入"); 
document.form.password.focus();
                return (false); 
}                 alert("密码正确"); 
window.location.href="http://baidu.com";


}
</script><TITLE>网站统计分析系统</TITLE><LINK rel="stylesheet" href="Info/Style.css">
<STYLE type="text/css">
<!--
.Button {  font-size: 9pt; color: #FFE7B3; background-color: #663300; height: 22px; width: 68px; BORDER-BOTTOM: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid;}-->
</STYLE>
</HEAD><BODY bgcolor="#663300" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<CENTER>
<LINK rel="stylesheet" href="Info/Style.css">
<DIV>
  <TABLE border="0" cellspacing="0" cellpadding="0" align="center">
    <TBODY><TR>
      <TD height="144" valign="top">
        <DIV id="Layer1" style="position:absolute; width:10px; height:10px; z-index:1"></DIV>
        <IMG src="Image/headbj.gif" width="777" height="95" border="0"> </TD>
    </TR>
  </TBODY></TABLE>
</DIV>
  <TABLE border="0" cellpadding="3" cellspacing="1" width="640" bgcolor="#000000">
    <TBODY> 
    <TR> 
      <TD align="center" bgcolor="#AB6C00"><font color="#FFFFFF">管理员登陆</font></TD>
    </TR>
    <TR> 
      <TD align="left" height="186" bgcolor="#663300"> 
        <FORM method="post" action="" name="form" onSubmit="return check()">
          <TABLE width="350" border="0" cellspacing="0" cellpadding="0" align="center">
            <TBODY><TR> 
              <TD width="116">&nbsp; </TD>
              <TD width="234">&nbsp;</TD>
            </TR>
            <TR> 
              <TD width="116">请输入密码:</TD>
              <TD width="234"> 
                <INPUT type="text" name="password" maxlength="50" size="25" class="biankuan">
                * &nbsp; </TD>
            </TR>
            <TR align="center"> 
              <TD colspan="2" height="23"> 
                <TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
                  <TBODY><TR> 
                    <TD width="35%" height="26">&nbsp;</TD>
                    <TD width="36%" height="26"> 
                      <INPUT type="submit" name="" value="确定登陆" class="Button"></TD>
                    <TD width="29%" height="26">&nbsp;</TD>
                  </TR>
                </TBODY></TABLE>              </TD>
            </TR>
          </TBODY></TABLE>
        </FORM>      </TD>
    </TR>
    <TR align="right"> 
      <TD bgcolor="#AB6C00" height="2"> 
        <P>&nbsp;</P>      </TD>
    </TR>
    </TBODY> 
  </TABLE>
  <BR>
<DIV align="center"><IMG src="Image/bqsy.gif" width="91" height="32" border="0"></DIV>
<BR>
</CENTER>
</BODY></HTML>关键就是那个JS的function check,当我密码输入正确的时候,都提示密码正确了,但是页面就是无法跳转到baidu.com,如果我单独把这个<script language="javascript">                alert("密码正确"); 
window.location.href="http://baidu.com";


}
</script>写在一个html文件里面,它能够跳转到baidu.com的,为什么在那个PHP文件里面就不行呢》找了好久不得原因,大侠帮帮忙

解决方案 »

  1.   

    你的表单
    <FORM method="post" action="" name="form" onSubmit="return check()">
    如果函数 check() 返回“真”就执行提交动作而函数 check() 中
      ...
      alert("密码正确"); 
      window.location.href="http://baidu.com";
    }
    js 的函数,若无显式的返回值时,将返回“真”(true)于是表单将被提交,之前的重定向就失去作用了
      

  2.   

    顶楼上的。
    你把 function check()
    {//结尾加上一句return false;
    return false;
    }
    再试试。
      

  3.   

    你这个代码写的是没问题,但是js本身是有问题的,我相信当你不输入密码或密码输入错误的时候也存在问题,就是 document.form.password.focus() 这个操作执行不了,我没说错吧,我以前也碰到过你这个问题,原因我说不清楚,但是解决方法是:请将alert方法单独写到一个函数里,比如:function getError(mess){
        alert(mess);
    }然后你就可以这么调用了getError("密码不能为空");
    你试试相信没有问题,因为咱俩的问题纯属一致
      

  4.   

    人家让你return 你倒好,跳转,那他让吗?还没付钱就想跑