首页 > 解决方案 > 新内容后触发 jQuery

问题描述

我以为我以前解决了它,因为我没有收到错误,但结果是。在这个网站上,我有add content buttons。系统在这些按钮中添加了一些文本,但我需要删除它们以匹配设计。

虽然我最初设法删除了文本,但它们在add content buttons重新加载时再次出现。我尝试onlick了事件委托,但到目前为止都没有工作。

jQuery(document).ready(function( $ ) {    
    //  Application add/edit form remove text from buttons
    $(".paragraphs-buttons button").html("<span class='icon glyphicon glyphicon-plus' aria-hidden='true'></span>");
    $(document).on("click",'.paragraphs-buttons button', (function() {
        $(".paragraphs-buttons button").html("<span class='icon glyphicon glyphicon-plus' aria-hidden='true'></span>");
        })
    );
});

在此处输入图像描述 在此处输入图像描述

标签: javascriptjquery

解决方案


***已编辑:要删除文本内容,请尝试text()在按钮内的 span 元素上使用函数。我还修复了代码语法,希望这次能正常工作。

jQuery(document).ready(function( $ ) {    
    //  Application add/edit form remove text from buttons
    $(".paragraphs-buttons button span").text("");
    $(document).on("click",'.paragraphs-buttons button', function () {
        $(".paragraphs-buttons button span").text("");
    });
});

***旧答案我不太明白您要实现的目标,但如果您只想在点击时显示它。在单击事件之前删除$(".paragraphs-buttons button").html("<span class='icon glyphicon glyphicon-plus' aria-hidden='true'></span>");,导致您在最初和单击发生时调用它两次。希望有帮助。

jQuery(document).ready(function( $ ) {    
    //  Application add/edit form remove text from buttons

    $(document).on("click",'.paragraphs-buttons button', (function() {
        $(".paragraphs-buttons button").html("<span class='icon glyphicon glyphicon-plus' aria-hidden='true'></span>");
        })
    );
});

要删除内容,您可以使用$(selector).html("");$(selector).empty();


推荐阅读