<!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语句不起作用?怎么回事?谢谢!
<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语句不起作用?怎么回事?谢谢!
直接if (username == password)不就好了
<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>