如何像在 jQuery 中一样在 YUI 中显示/隐藏元素?

发布于 2024-10-09 12:23:38 字数 454 浏览 0 评论 0原文

在 jQuery 中,当我想显示或隐藏某些内容时,我会这样做:

$('#elementId').show();
$('#elementId').hide();

How do I do this with YUI?我尝试过 YAHOO.util.Dom.get('elementId').hide(),询问我的同事,查看文档,并搜索 Google,但我发现没有任何帮助。从文档来看,这看起来应该可行

YAHOO.util.Dom.get('elementId').setStyle('display', 'none')

,但当然不行。我能想到的就是这个,这很糟糕,因为我没有使用框架:

document.getElementById('elementId').style.display = 'none';

In jQuery, when I want to show or hide something, I do this:

$('#elementId').show();
$('#elementId').hide();

How do I do this with YUI? I've tried YAHOO.util.Dom.get('elementId').hide(), asked my co-workers, looked at the documentation, and searched Google, and I've found nothing helpful. From the documentation, it looks like this should work

YAHOO.util.Dom.get('elementId').setStyle('display', 'none')

but of course it does not. All I can think of is this, which sucks because then I'm not using a framework:

document.getElementById('elementId').style.display = 'none';

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

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

发布评论

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

评论(2

淡淡の花香 2024-10-16 12:23:38

您可以省略 Dom.get。

YAHOO.util.Dom.setStyle('elementId', 'display', 'none');

仅供参考,在 YUI 3 中(截至 3.3.0pr3)

Y.one('#elementId').hide();

对于 YUI 3.2-

Y.one('#elementId').setStyle('display', 'none');

You can omit the Dom.get.

YAHOO.util.Dom.setStyle('elementId', 'display', 'none');

FYI, in YUI 3 (as of 3.3.0pr3)

Y.one('#elementId').hide();

For YUI 3.2-

Y.one('#elementId').setStyle('display', 'none');
影子是时光的心 2024-10-16 12:23:38

显然我必须这样做:

YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get('elementId'), 'display', 'none');

可笑且不必要的长,但它似乎有效。

Apparently I have to do this:

YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get('elementId'), 'display', 'none');

Ridiculously and unnecessarily long, but it seems to work.

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