JS菜鸟问题,我看视频,跟着视频敲的代码,不知道为什么就是不行,那位高手帮我看看啊,谢谢啦
<html><head><scripttype="text/javascript">functioncan(){varname=document.getElementsB...
<html>
<head>
<script type="text/javascript">
function can(){
var name=document.getElementsById(name1);
var pwd=document.getElementById(pwd1);
var repwd=document.getElementById(repwd1);
if(name.value.length == 0){
alert("the name can't be blank");
return false;
}
if(pwd.value.length<6){
alert("your password is valid");
return false;
}
if(repwd.value.length<6){
alert("your repassword is valid");
return false;
}
if(repwd.value!=pwd.value){
alert("your password isn't match");
return false;
}
return true;
}
</script>
</head>
<body>
<form onSubmit="can()">
name:<input type="text" name="name" id="name1"/>
password:<input type="password" name="pwd" id="pwd1"/>
re-password:<input type="password" name="repwd" id="repwd1"/>
<input type="submit" value="submit"/>
</form>
</body>
</html> 展开
<head>
<script type="text/javascript">
function can(){
var name=document.getElementsById(name1);
var pwd=document.getElementById(pwd1);
var repwd=document.getElementById(repwd1);
if(name.value.length == 0){
alert("the name can't be blank");
return false;
}
if(pwd.value.length<6){
alert("your password is valid");
return false;
}
if(repwd.value.length<6){
alert("your repassword is valid");
return false;
}
if(repwd.value!=pwd.value){
alert("your password isn't match");
return false;
}
return true;
}
</script>
</head>
<body>
<form onSubmit="can()">
name:<input type="text" name="name" id="name1"/>
password:<input type="password" name="pwd" id="pwd1"/>
re-password:<input type="password" name="repwd" id="repwd1"/>
<input type="submit" value="submit"/>
</form>
</body>
</html> 展开
2个回答
展开全部
var name=document.getElementsById("name1");
var pwd=document.getElementById("pwd1");
var repwd=document.getElementById("repwd1");
注意引号,,不然计算机会以为那是变量
var pwd=document.getElementById("pwd1");
var repwd=document.getElementById("repwd1");
注意引号,,不然计算机会以为那是变量
追问
还是不行啊,直接就提交了,没有任何的反应哦
追答
function can(){
if(Form1.name.value.length == 0){
alert("the name can't be blank");
return false;
}
if(Form1.pwd.value.length
name:
password:
re-password:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询