Jquery 复杂选择器,匹配类名切换的父级的子级?
我下载了一个jquery可折叠面板脚本(用作菜单),它工作得很好,但是我将它与.NET结合使用,并尝试根据您正在查看的页面来扩展它的面板,但是无论我尝试过所有组合,我似乎都无法选择该东西。 HTML 如下所示:
<div class="collapsibleContainer app ui-widget" title="1990">
<div class="collapsibleContainerTitle app ui-widget-header">
<div>▸1990</div>
</div>
<div class="collapsibleContainerContent app ui-widget-content" style="display: none; ">
Text Stuff
</div>
</div>
现在,在运行初始内容后,在此脚本上,编写此行将成功切换所有面板:
$(".collapsibleContainerContent").slideToggle();
但是,当然,因为页面上有多个这些面板,所以我不想要它们全部切换,仅切换与我正在查看的特定页面相关的切换。我这样尝试:
$(".collapsibleContainerTitle.app.ui-widget-header:contains('<%= Decade %>')").parent().slideToggle();
$(".collapsibleContainer.app.ui-widget-header[title='<%= Decade %>'] > .collapsibleContainerContent").slideToggle();
在许多其他组合中。我以前从未使用过如此复杂的选择器(至少对我来说是复杂的)。我该怎么办?我需要选择适当的十年容器内的 .collapsibleContainerContent
和 slipToggle() 。
我已经确认传递给脚本的 .net 变量是正确的,在查看源代码时它确实显示 1990。那么我做错了什么?谢谢。
编辑:澄清一下,年份是动态的,这就是我必须匹配我的数据,所以我需要至少从 Container by attribute title 或 ContainerTitle by :contains 与年份的基本选择开始,但我需要以 ContainerContent 选择结束,以便我可以切换它。
I downloaded a jquery collapsible panel script (used as a menu), which I've got working fine, however I am using it in conjunction with .NET and trying to have a certain panel based on the page you are viewing to expand it's panel, however I can't seem to select the thing no matter all the combinations I have tried. Here is what the HTML looks like:
<div class="collapsibleContainer app ui-widget" title="1990">
<div class="collapsibleContainerTitle app ui-widget-header">
<div>▸1990</div>
</div>
<div class="collapsibleContainerContent app ui-widget-content" style="display: none; ">
Text Stuff
</div>
</div>
Now on this script after I run the initial stuff, writing this line will successfully toggle all the panels:
$(".collapsibleContainerContent").slideToggle();
However, of course because there are multiples of these panels on a page, I don't want them all toggled, just the one that is relevant to the specific page I am viewing. I tried this like so:
$(".collapsibleContainerTitle.app.ui-widget-header:contains('<%= Decade %>')").parent().slideToggle();
$(".collapsibleContainer.app.ui-widget-header[title='<%= Decade %>'] > .collapsibleContainerContent").slideToggle();
Among a slew of other combinations. I never had to use selectors this complex before (at least for complex for me). How can I do? I need to select the .collapsibleContainerContent
and slideToggle() it that is within the appropriate decade container.
I have confirmed that the .net variable being passed to the script is correct, when viewing the source it does say 1990. So what am I doing wrong? Thanks.
Edit: Clarification, the year is dynamic and that is what I have to match my data, so I need will be starting at least with the base select of either the Container by attribute title or ContainerTitle by :contains with the year, but I need to end with the ContainerContent selection so I can toggle it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要像这样重写...
..空格非常重要!
You need to re-write like this...
..the spaces are all-important!
成功了。
Did the trick.