zoukankan      html  css  js  c++  java
  • jq动态增加的button标签click回调失效的问题,即动态增加的button标签绑定事件$("button.class").click(function)无效

    对于新增加的页面元素,改变了页面结构,如果是使用老办法$("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>');
    });
  • 相关阅读:
    Linux--sed命令
    Linux--cut命令
    Android--aapt命令
    Shell--基础知识
    Linux--vim编辑器和文件恢复
    Linux--基本命令
    Linux--添加用户
    Linux--网络配置
    SpringCloud--Ribbon负载均衡
    第一阶段冲刺4
  • 原文地址:https://www.cnblogs.com/alanleung/p/6837424.html
Copyright © 2011-2022 走看看