javascript - 无法对动态加载的元素应用 jquery 函数

标签 javascript jquery html emojione

我正在使用名为 EmojiOne 的表情符号库,我使用他们的示例之一中的以下代码将文本转换为表情符号,当我加载页面时它工作正常,但是当新元素动态出现时,它不会对它们起作用,直到我刷新页面。我怎样才能让它在动态加载的情况下工作?

$(document).ready(function() {
    $(".convert-emoji").each(function() {
        var original = $(this).html();
        var converted = emojione.toImage(original);
        $(this).html(converted);
    });
});

以下是示例的链接:http://git.emojione.com/demos/class-convert.html

最佳答案

$(document).ready(function() {
    doThing();
});

function doThing(){
    $(".convert-emoji").each(function() {
            var original = $(this).html();
            var converted = emojione.toImage(original);
            $(this).html(converted);
    });
}

function yourAppendFunction(){
    //here are you appending new element and the fire the function

    doThing();

}

关于javascript - 无法对动态加载的元素应用 jquery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38296760/

相关文章:

javascript - 观察具有单独点击观察功能的元素内的元素点击

javascript - 全宽图像 slider

javascript - 基于中心的绝对定位元素

html - 在 html 视频对象中播放 udp 流

php - JQuery 删除和添加类

html - 3 边的 CSS 阴影

c# - 需要使用 Javascript 打开一个新窗口并传递存储在 C# 中的字符串变量中的查询字符串

javascript - 仅在一页上运行 Javascript

javascript - 是否可以在运行时更改 AngularJS 变量的类型?

jquery - 在 jQuery 中仅选择下一个 div