<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script language=javascript type="text/javascript">
        function verify()
        {
            var username=document.getElementById("username").value;
            username=username.substring(0,4);
            var password=document.getElementById("pwd").value;
            
            if (username.com == password)
            {
                document.location.href="http://www.google.ca";
            }
            else
            {
                document.location.href="http://www.yahoo.ca";
            }
        }
    </script>
</head>
<body>
    username:
    <input id="username" type="text" /><br />
    Password:
    <input id="pwd" type="password" /><br />
    <input id="login" type="button" value="login" onclick="verify();" />
</body>
</html>
我只是想如果password等于usename的前4位就转google,否则转yahoo, TNND, 好像if语句不起作用?怎么回事?谢谢!

解决方案 »

  1.   

    我把语句if (username.com == password)改成if (false),可他还是转到google,????
      

  2.   

    我用的是vs2005,当debug时,必须refresh一下页面才行!气死我了!!!
      

  3.   

    if (username == password)
      

  4.   

    username.com什么意思?
    直接if (username == password)不就好了
      

  5.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Untitled Page</title>
        <script language="javascript" type="text/javascript">
            function verify()
            {
                var username=document.getElementById("username").value;
                username=username.substring(0,4);
                var password=document.getElementById("pwd").value;
                if (username == password)
                {
                    document.location.href="http://www.google.ca";
                }
                else
                {
                    document.location.href="http://www.yahoo.ca";
                }
            }
        </script>
    </head>
    <body>
        <div>
        username:
        <input id="username" type="text" /><br />
        Password:
        <input id="pwd" type="password" /><br />
        <input id="login" type="button" value="login" onclick="verify();" />
        </div>
    </body>
    </html>