zepto點選檢視密碼明文效果程式碼例項

admin發表於2017-02-20

分享一段程式碼例項,它實現了點選按鈕檢視密碼明文的效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<script type="text/javascript" src="js/zepto.min.js"></script>
<script type="text/javascript">
$(function() {
  (function() {
    $.fn.showpassWord = function() { //檢視密碼
      function Seepasswrod(elemnts) {
        this.elemnts = elemnts;
        this.init();
      };
      Seepasswrod.prototype = {
        init: function() {
          var m = this
          this.shouEvent(m);
        },
        shouEvent: function(m) {
          m.elemnts.on("tap click", function() {
            var type = m.elemnts.parent().find(".passwords").attr("type");
            if (type == "password") {
              m.elemnts.parent().find(".passwords").attr("type", "text");
            } else if (type == "text") {
              m.elemnts.parent().find(".passwords").attr("type", "password");
            }
          });
        },
      };
      return this.each(function() {
        new Seepasswrod($(this))
      });
    };
  })(Zepto);
  $(".seepassword").showpassWord();
});
</script>
</head>
<body>
<div class="ui-password">
  <input type="password" name="pw" class="passwords">
  <button class="seepassword">檢視密碼</button>
</div>
</body>
</html>

相關文章