<form name="form" action="#"><input type="password" id="pwd1" /> <input type="password" id="pwd2" /> <input type="submit" value="提交" onclick="return check()" /> </form> <script> function check(){ var pwd1 = document.getElementById("pwd1").value; var pwd2 = document.getElementById("pwd2").value; if(pwd2!=pwd1){ //这里我只判断是否相等了 没做其他判断 alert("两次输入的密码不一致,请检查!"); return false; //return false是用来阻止表单提交的 } return true; } </script>
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)