Jquery或者JS方法驗證密碼是否一致

來源:互聯網
上載者:User

標籤:lin   是否一致   bsp   ext   輸入   log   引用   blog   boot   

 

 

<script src="../JS/jquery-3.2.0.js" type="text/javascript" ></script><script src="../JS/bootstrap.min.js"></script><link type="text/css" rel="stylesheet" href="../css/bootstrap.min.css" /><body><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/></body>

 JS方式 onkeyup="validate()"是引用方法的方式

<script>function validate() {var pwd1 = document.getElementById("pwd").value;var pwd2 = document.getElementById("pwd1").value;<!-- 對比兩次輸入的密碼 -->if(pwd1 == pwd2)  {document.getElementById("tishi").innerHTML="<font color=‘green‘>兩次密碼相同</font>";document.getElementById("button").disabled = false;     }else {document.getElementById("tishi").innerHTML="<font color=‘red‘>兩次密碼不相同</font>";document.getElementById("button").disabled = true;  }}</script>

 Jquery方法

<script>function validate() {         var pwd = $("#pwd").val();    var pwd1 = $("#pwd1").val();<!-- 對比兩次輸入的密碼 -->    if(pwd == pwd1)     {        $("#tishi").html("兩次密碼相同");         $("#tishi").css("color","green");    $("#xiugai").removeAttr("disabled");     }else {        $("#tishi").html("兩次密碼不相同");         $("#tishi").css("color","red")          $("button").attr("disabled","disabled");         }}</script>

 

Jquery或者JS方法驗證密碼是否一致

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.