javascript - JQuery 在创建 DOM 元素后做一些事情 - DOMNodeInserted 不工作

标签 javascript jquery html

好的,我有一个空的 div,稍后会动态填充一些内容:

<div class="row no-margin">
    <div id="sensorInfoContent">
    </div>
</div>

稍后它会填充一些其他的 div 和内容。我需要选择这个子 div:

<div class="circDash" id="batPerc" accesskey="30" style="height:100px; background-color:#000000;">

然后在上面调用这个函数:

$(*DIV*).circleProgress({
            value: 0.75,
            size: 80,
            fill: {
                gradient: ["red", "orange"]
           }
        });

我尝试在点击时执行此操作,并且它正在运行。像这样:

$('#sensorInfoContent').on("click", ".circDash", function() {

    $(this).circleProgress({
        value: 0.75,
        size: 80,
        fill: {
            gradient: ["red", "orange"]
       }
    });
});

但我需要在动态添加元素之后完成,而不是在单击时完成。试过 DOMNodeInserted,它不工作:

    $('#sensorInfoContent').on("DOMNodeInserted", ".circDash", function() {

        $(this).circleProgress({
            value:

 0.75,
        size: 80,
        fill: {
            gradient: ["red", "orange"]
       }
    });
}); 

有什么想法、替代方案或解决方法吗?

最佳答案

只需手动触发点击

$('#sensorInfoContent').on("click", ".circDash", function() {

    $(this).circleProgress({
        value: 0.75,
        size: 80,
        fill: {
            gradient: ["red", "orange"]
       }
    });
});

像这样

$('.circDash').trigger('click');

关于javascript - JQuery 在创建 DOM 元素后做一些事情 - DOMNodeInserted 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35313944/

相关文章:

javascript - 从子字符串中删除单词

jquery - 如何控制动态加载到iframe中的内容的CSS?

html - 如何从 HTML 执行 shell 命令?

html - Firefox/IE 中的列布局问题,但 Chrome 中没有

JavaScript 下拉移动链接

javascript - 单击时使用 jQuery 使用 HTML 更新 DIV

javascript - 声明后执行命名函数

javascript - 用于从文件名中删除 Wordpress 图像大小调整的正则表达式或标准子字符串解决方案

javascript - 在 JQuery 中显示和隐藏对象

html - 如何用图像填充手机中的背景