<html>
<head>
<meta charset="UTF-8">
<title>表单实验</title>
<script>
function check(form) {
var p1 = form.passwd1
var p2 = form.passwd2
if (p1.value != p2.value) {
p2.oninvalid()
return false
}
return true
}
onload = function() {
var p2 = document.forms["my_f1"].passwd2
p2.oninvalid = function() {
this.setCustomValidity("密码不一致,请重新输入")
}
p2.oninput = function() {
this.setCustomValidity("")
}
}
</script>
</head>
<body>
<form action="" method="post" name="my_f1" onsubmit="return check(this)">
<p>密码:
<input type="password" required="true" name="passwd1" />
</p>
<p>密码确认:
<input type="password" required="true" name="passwd2" />
</p>
<p>
<input type="submit" value="提交" />
</p>
</form>
</body>
</html>
楼主 你把js 里面的函数改一下 改成下面这样就可以了<script>
function check() {
var pass1=document.getElementById("pass1")
var pass2=document.getElementById("pass2")
var email=document.getElementById("email")
if(pass1.value!=pass2.value){
pass2.setCustomValidity("密码不一致。")
}
else if(pass1.value==pass2.value){
pass2.setCustomValidity("")
}
else if(!email.checkValidity()){
email.setCustomValidity("请输入正确的Email地址。")
}
else{
email.setCustomValidity("")
}
}
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)