好的,我有一个空的 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/