艺博会(密码小眼睛点击显示隐藏)

<li class="infoLi">
  <div class="infoText">修改密码</div>
  <input class="store Pasw" type="password" placeholder="请输入最新修改密码" />
  <div class="toTextEye"></div>
</li>

 

第一种方法:

$(".toTextEye").click(function(){
  $(this).toggleClass("toPaswEye");
  var aa = $(this).prev().attr('type');
  if(aa=="password"){
    $(this).prev().attr('type','text');
  }else{
    $(this).prev().attr('type','password');
  }
});

第二种方法:

//单击切换密码显示或隐藏
$(document).on("click", ".toTextEye" ,function(){

  //$(".toTextEye").on("click", function(){

  $(this).addClass("toPaswEye");
  $(this).prev().attr('type','text');
});
//单击切换密码显示或隐藏
$(document).on("click", ".toPaswEye" ,function(){

  //$(".toPaswEye").on("click", function(){
  //console.log("1111")
  $(this).removeClass("toPaswEye");
  $(this).prev().attr('type','password');
})

$(".toPaswEye").on("click", function(){直接绑定点击事件是不行的 , 因为初始化的时候没有.toPaswEye这个类名。(再看看事件代理的相关知识)

 

第三种:(没有进行测试)给<div class="toTextEye" ></div>  加个data=“1”

// console.log($(this).attr('data'));
// if (1 == $(this).attr('data')) {
// $(this).addClass("toPaswEye");
// $(this).prev().attr('type','text');
// $(this).attr('data','2')
// } else {
// $(this).removeClass("toPaswEye");
// $(this).prev().attr('type','password');
// $(this).attr('data','1')
// }

 

第四种:

//单击切换密码显示或隐藏
$(".toTextEye").click(function(){
if($(this).hasClass("toTextEye")== true){
alert(1)
$(this).addClass("toPaswEye");
$(this).removeClass("toTextEye");
$(this).prev().attr('type','text');
}else{
alert(2)
$(this).removeClass("toPaswEye");
$(this).addClass("toTextEye");
$(this).prev().attr('type','password');
}
});

 

转载于:https://www.cnblogs.com/ourLifes/p/9561819.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值