自动隐藏可见子元素

发布于 2024-08-10 23:27:13 字数 693 浏览 3 评论 0原文

我正在使用 HTML、JavaScript 和 CSS 进行一些原型设计。该原型是在移动设备上运行的应用程序套件。每个屏幕都内置在其自己的 DIV 中。有一个主屏幕,几个屏幕,等等。

用户应该能够随时转储到主屏幕。每个屏幕中都有某些默认可见的元素,以及基于某些操作专门设置为可见的其他元素。

我遇到的问题是,当将屏幕 DIV 之一设置为隐藏时,我仍然可以看到我专门设置为可见的该 DIV 的子元素。我知道有一个预先存在的代码隐藏了目标 DIV 的所有子元素,但我只想隐藏我已经设置为可见的子元素。

有没有代码可以帮助我解决这个问题?我可以构思一种围绕此进行编程的方法,但我不想重新发明轮子。

示例 HTML:

<div id="parentDiv">
  <span id="childElement" style="visibility:hidden"></span>
</div>

示例 JavaScript:

$('childElement').style.visibility = 'visible';
$('parentDiv').style.visibility = 'hidden';

完成此示例后,我仍然可以看到 childElement。

注意:在 Windows XP 上使用 Opera

I am doing some prototyping using HTML, JavaScript and CSS. The prototype is for an application suite to run on a mobile device. Each screen is built in it's own DIV. There is one home screen, several screens off that, et cetera.

The user should be able to dump out to the home screen at any time. There are certain elements in each screen that are visible by default, and other elements that are specifically made visible, based off certain actions.

The issue I am having is that when setting one of the screen DIVs to hidden, I can still see the child elements of that DIV that I have specifically made visible. I understand there is pre-existing code which hides all child elements of a target DIV, but I only want to hide the one's I've made visible.

Is there code out there which will help me with this? I can conceptualize a way I could program around this, but I don't want to reinvent the wheel.

Sample HTML:

<div id="parentDiv">
  <span id="childElement" style="visibility:hidden"></span>
</div>

Sample JavaScript:

$('childElement').style.visibility = 'visible';
$('parentDiv').style.visibility = 'hidden';

After doing this sample, I can still see childElement.

Note: using Opera on Windows XP

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

败给现实 2024-08-17 23:27:13

尝试使用

$('parentDiv').style.display = "none";

then 使其可见

$('parentDiv').style.display = "block"

try using

$('parentDiv').style.display = "none";

then to make it visible

$('parentDiv').style.display = "block"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文