js两次输入密码验证,可以参考如下代码:
<FORM METHOD=POST ACTION=""><input type="password" id="input1">
<input type="password" id="input2">
<input type="button" value="test" onclick="check()">
</FORM>
<script>
function check()
{
with(document.all){
if(input1.value!=input2.value)
{
alert("false")
input1.value = ""
input2.value = ""
}
}
}
</script>
JavaScript验证两次输入密码是否相同,通过去判断两次输入的密码是否相同来实现,
下面是html代码<FORM METHOD=POST ACTION="">
<input type="password" id="input1">
<input type="password" id="input2">
<input type="button" value="test"
onclick="check()">
</FORM>下面是javascript的代码<script>
function check()
{
with(document.all){
if(input1.value!=input2.value)
{
alert("false")
input1.value = ""
input2.value = ""
}
else document.forms[0].submit()
}
<input type="submit" value="注册" onclick="conpwd()" />把onclick事件去掉function conpwd(){
p1 = document.getElementById("p1")
p2 = document.getElementById("p2")
if(p2.value != p1.value){
alert("两次密码必须一致")
return false
}
return true;
}
这样就可以了