JQuery:隐藏/显示非活动选项卡中的元素
我有 3 个标签。除了其他元素之外,它们每个都有一个名为可选的 div。 可选最初是使用Javascript隐藏的,我不想使用CSS(这样如果js被禁用,div将根本不会被隐藏)。
所以我用它来隐藏可选
$(function(){
$('#optional').hide();
});
现在,这在第一个选项卡上工作得很好,但不会在接下来的两个选项卡上隐藏。它们都有相同的代码,没有命名冲突,也没有报告 JavaScript 错误。
知道我做错了什么吗?
I've got 3 tabs. Each of them have a div called optional, apart from other elements.
optional is initially hidden using Javascript, I dun wanna use CSS ( this is so if js is disabled, the div won't be hidden at all ).
So I use this to hide optional
$(function(){
$('#optional').hide();
});
Now, this works just fine on the first tab but won't hide on the next two tabs. They've all got the same code, no naming conflicts and no javascript errors reported.
Any idea what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Classname 而不是
id
,因为 ID 必须是唯一的。通过 DOM/JS,如果不是 html。Edited: to change
...('.optional')...
to...('div.optional')...
which should reduce the time it takes the function to work (since it's looking through only one set of tags<div>
rather than all of them, examining them for their class-name.Classname instead of
id
, since IDs are required to be unique. By the DOM/JS, if not html.Edited: to change
...('.optional')...
to...('div.optional')...
which should reduce the time it takes the function to work (since it's looking through only one set of tags<div>
rather than all of them, examining them for their class-name.