javascript - 使用 MutationObserver 在 DOM 元素更新上显示模式
问题描述
我只想在具有相同类的任何 DOM 元素之一被更新后才显示模式弹出窗口。我猜 MutationObserver 是最好的工具吗?这是我到目前为止所得到的,但它不起作用......
// Get the modal
var modal = document.getElementById("save-search-modal");
// select the target nodes for mutation observing
var target = document.getElementsByClassName("sidx-pill-value")[0];
// When .sidx-pill-value is updated, open the modal
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
modal.style.display = "block";
});
});
// configuration of the observer:
var config = { subtree: true, characterData: true, attributes: true, childList: true }
// pass in the target node, as well as the observer options
observer.observe(target, config);
解决方案
推荐阅读
- mysql - MYSQL - How to match the country with the highest deaths for a unique list of continents
- python - 在 Python 中使用 aiogram bot-framework 从 Telegram 下载文件
- python - 关于在 python 模块中从 .env 存储和检索的路径的最佳实践
- unity3d - 如何在前进的同时实例化游戏对象后面的游戏对象
- r - 在 R Shiny 中,如何在单击操作按钮后触发 UI 中呈现的条件面板中的更改?
- java - 执行 OncePerRequestFilter 后请求链接不起作用
- api - 如何使用 REST API 和 HATEOAS 实现多步表单
- c++ - 使用 LibTorch (PyTorch) 时在 C++ 中将 at::Tensor 转换为双精度
- netlogo - 是否可以将邻居命令与代理路由一起使用?
- c - 为什么将字符串文字分配为结构的字符数组成员的值会产生错误?