<div class="form-group">
<label class="col-sm-2 control-label font">新密码</label>
<div class="col-xs-10">
<input type="password" class="form-control bt" name="pwd" id="pwd" placeholder="请设置新密码">
</div>
</div><br/><br/><br/>
<div class="form-group">
<label class="col-sm-2 control-label font">确认新密码</label>
<div class="col-xs-10">
<input type="password" class="form-control bt" name="pwd" id="pwd1" placeholder="请再次填写新密码" onkeyup="validate()"><span id="tishi"></span>
</div>
</div><br/><br/>
<button type="button" class="btn btn-primary btn-lg btn-block xg" id="xiugai" >修改</button>
JS写法
1 function validate() {
2 var pwd1 = document.getElementById("pwd").value;
3 var pwd2 = document.getElementById("pwd1").value;
4
5 <!-- 对比两次输入的密码 -->
6 if(pwd1 == pwd2)
7 {
8 document.getElementById("tishi").innerHTML="<font color='green'>两次密码相同</font>";
9 document.getElementById("button").disabled = false;
10 }
11 else {
12 document.getElementById("tishi").innerHTML="<font color='red'>两次密码不相同</font>";
13 document.getElementById("button").disabled = true;
14 }
15 }
JQuery写法
1 function validate() {
2
3 var pwd = $("#pwd").val();
4 var pwd1 = $("#pwd1").val();
5 <!-- 对比两次输入的密码 -->
6 if(pwd == pwd1)
7 {
8 $("#tishi").html("两次密码相同");
9 $("#tishi").css("color","green");
10 $("#xiugai").removeAttr("disabled");
11 }
12 else {
13 $("#tishi").html("两次密码不相同");
14 $("#tishi").css("color","red")
15 $("button").attr("disabled","disabled");
16 }
17 }