我正在使用名为 EmojiOne 的表情符号库,我使用他们的示例之一中的以下代码将文本转换为表情符号,当我加载页面时它工作正常,但是当新元素动态出现时,它不会对它们起作用,直到我刷新页面。我怎样才能让它在动态加载的情况下工作?
$(document).ready(function() {
$(".convert-emoji").each(function() {
var original = $(this).html();
var converted = emojione.toImage(original);
$(this).html(converted);
});
});
最佳答案
$(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/