对于新增加的页面元素,改变了页面结构,如果是使用老办法$("button.class").click(function)去监听新的button标签事件,会失效。

笔者的应用是文字的显示和隐藏之间的切换,给出我的代码:

解决办法:

$(document).on("click",".showPwd",function () {
//                alert("show now:" + );
                $(this).parent().html(
                        $(this).attr("key")+'  '+
                        '<button class="btn btn-default btn-sm hidePwd" key="'+$(this).attr("key")+'"><span class="glyphicon glyphicon-eye-close"></span></button>');
});

$(document).on("click",".hidePwd",function () {
                //alert("show now");
                $(this).parent().html('<button class="btn btn-default btn-sm showPwd" key="'+$(this).attr("key")+'"><span class="glyphicon glyphicon-eye-open"></span></button>');
});

 

相关文章:

  • 2022-12-23
  • 2021-11-10
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2022-02-23
猜你喜欢
  • 2022-12-23
  • 2021-04-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2021-12-29
相关资源
相似解决方案