javascript - 无法隐藏 z-index 设置为 1 的同级元素
问题描述
我有一个覆盖另一个元素的模式。下部元素上的关闭按钮的 z-index 设置为 1。当我创建模式时,这个原始关闭按钮仍然嵌套在新模式及其新关闭按钮的顶部。
我尝试在 dom 中抓取这个元素并将其隐藏,但由于它不是父元素,我不知道如何。
编辑:这是伪代码......问题是如何删除覆盖的兄弟元素。
<div>
<div>
<img style={{z-index: 1; position: fixed;}}>close button (sibling, this one needs to be moved underneath or hidden)</img>
</div>
<div>
<div>
<div>
<img style={{z-index: 1; position: relative;}}>close button (popup modal)</img>
</div>
</div>
已解决:事实证明,无论它在 DOM 层次结构中的哪个位置(添加 id 之后),我都可以通过它的 id 抓取元素并切换它的显示。不知道为什么我不这么认为。¯_(ツ)_/¯
const closeBtn = document.getElementById('closeBtnSibling');
closeLessonBtn.style.display = 'none';
和
closeLessonBtn.style.display = null;
解决方案
style={z-index: 1; position: fixed;}
->style={{zIndex: 1, position: 'fixed'}}
React 内联样式参考:https ://reactjs.org/docs/dom-elements.html#style
推荐阅读
- javascript - 我将如何使用 json 上传本地文件
- c# - 使用存储过程插入并返回输出参数
- batch-file - 在批处理脚本中使用 sqlcmd 运行带有输出文件的多个脚本
- openmp - 为什么这个并行 for 循环不给我加速?
- python - 由于未找到模块“pd.core.dtypes.common”,本地 Ubuntu 机器拒绝导入 Pandas
- java - 来自 textView 的 getIdentifier() 返回 null
- java - 试图理解 Java 中的命名空间是什么
- java - 如何在 Hive 2 中将数据插入到复杂数据类型“Struct”中
- wcf - WCF:无法为具有权限“dev.xxxxx.com”的 SSL/TLS 安全通道建立信任关系
- java - 测量异步方法的执行时间