javascript - jQuery 无法识别类更改

标签 javascript jquery html

好的,我有一个编辑按钮,当我按下它时,它会变为“完成”按钮。

这一切都是由 jQuery 完成的。

        $(".icon-pencil").click(function() {
            var pencil = $(this);
            var row = $(this).parent('td').parent('tr');
            row.find('td').not(":nth-last-child(2)").not(":last-child").each(function() {
                $(this).html("hi");
            });

            pencil.attr('class', 'icon-ok-sign');
        });

        //  save item
        $(".icon-ok-sign").click(function() {
            alert("hey");
        });

当我按下“编辑”(“.icon-pencil”)按钮时,其类更改为 .icon-ok-sign (我可以在 Chrome 控制台中看到),

但是当我点击它时,没有显示任何警报。

当我创建<span class="icon-ok-sign">press</span>时并按下它,将显示一条警报。

如何解决?

最佳答案

尝试使用 $( document ).on( "click", ".icon-ok-sign", function() {...

关于javascript - jQuery 无法识别类更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20543527/

相关文章:

javascript - 如何在 Angular 2+ 中更改 anchor 的 html 元素后设置 @ViewChild ('anchor_name' )?

javascript - 返回在循环中调用的回调结果的串联

javascript - 如何防止在一条路由中启动的慢速 $http 在用户更改路由后可能解析?

javascript - 如何仅使用 div 的高度和宽度来查找内容长度?

html - 缺少子菜单

html - 使用 bootstrap 3 全屏垂直和水平对齐

javascript - 使用 Turbolinks 5 导航时 Disqus 评论显示 "Browser not supported"

javascript - 动态创建多个div结构

jquery - 将一个表单附加到另一个 jQuery

jquery - Bootstrap 日期选择器仅显示特定月份