gpt4 book ai didi

javascript - jQuery 不选择 div 类

转载 作者:太空宇宙 更新时间:2023-11-03 21:00:51 25 4
gpt4 key购买 nike

试图制作一个简单的切换菜单,但我似乎无法使用这段 jQuery 来隐藏/显示子菜单:

$(".topic news").mouseup(function(){
$(".feed groups").hide("fast", function(){
$(".feed messages").hide("fast");
$("ul.feed news").toggle("fast");
});
});

这是相应的 HTML:

<div class="topic news">
<span>News Feed</span>
</div>
<ul class="feed news">
<li>News item #1</li>
<li>News item #1</li>
<li>News item #1</li>
<li>News item #1</li>
<li>News item #1</li>
</ul>

有什么想法吗?

最佳答案

要选择具有多个类的 div,无论是在 CSS 还是 jQuery 中,您都可以连接多个类选择器:

// Notice the dot instead of the space in all these selectors
$(".topic.news").mouseup(function(){
$(".feed.groups").hide("fast", function(){
$(".feed.messages").hide("fast");
$("ul.feed.news").toggle("fast");
});
});

关于javascript - jQuery 不选择 div 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2924791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com