使用 jQuery 事件显示和隐藏
有几个高级 jQuery 插件可以通过相应的 id 或类过滤
。这确实是基于一个简单的 jQuery 想法,但我不知道如何实现它。考虑一个用于显示/隐藏内容的菜单<ul id="filters" class="menu" indicator="filter">
<li><a href="#filter" indicator="*" class="selected">All</a></li>
<li><a href="#filter" indicator=".first">First</a></li>
<li><a href="#filter" indicator=".third">Third</a></li>
</ul>
,我们想要控制内容的显示:
<div class="box first">Something</div>
<div class="box first third">Something</div>
<div class="box third">Something</div>
执行此操作的最简单的 jQuery Javascript 代码是什么?
默认情况下,所有
都会显示,当我们从菜单中单击
(例如FIRST)时,jQuery将过滤< ;div>
仅显示该类为“第一个”的
。There are several advanced jQuery plugins which filter <div>
s by corresponding id or class. This is indeed based on a simple jQuery idea, but I am not sure how to implement it. Consider a menu to show/hide the content as
<ul id="filters" class="menu" indicator="filter">
<li><a href="#filter" indicator="*" class="selected">All</a></li>
<li><a href="#filter" indicator=".first">First</a></li>
<li><a href="#filter" indicator=".third">Third</a></li>
</ul>
and we want to control the display of contents:
<div class="box first">Something</div>
<div class="box first third">Something</div>
<div class="box third">Something</div>
What is the simplest jQuery Javascript code to do so?
By default, all <div>
s are shown, when we click on a <li>
from menu (e.g. FIRST), jQuery will filter the <div>
s to only show <div>
s in which the class is "first".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不要使用属性“indicator”,因为它不存在。使用如下所示的类元素。也不需要 A 元件。
然后你的脚本
Don't use attribute "indicator" as it doesn't exist. Use the class element as below. Also the A elements are not needed.
Then your script
参考
Reference
使用
class
属性而不是indicator
并尝试以下操作:要使其正常工作,您必须将
all
类分配给您的第一个 LI,如下所示以及您所有的 DIV。希望这有帮助!Use the
class
attribute instead ofindicator
and try the following:for this to work you would have to assign an
all
class to your first LI as well as all of your DIVs. Hope this helps!试试这个代码,
try this code,