jQuery 鼠标悬停 +鼠标移开+单击以更改多个 (2)
我有一个
,如下所示:
列表,其中包含 2 个
HTML:
<div id="list">
<ul>
<li>name1</li>
<li>title1</li>
</ul>
<ul>
<li>name2</li>
<li>title2</li>
</ul>
<ul>
<li>name3</li>
<li>title3</li>
</ul>
<ul>
<li>name4</li>
<li>title4</li>
</ul>
and so on...
</div>
CSS:
#list {color: grey}
.name {color: black}
.title {color: red}
输出如下所示(文本均为灰色):
姓名1 标题1
姓名2 标题2
姓名3 标题3
name4 title4
当您将鼠标悬停任何
都会获得一个应用于外观的类像这样(斜体是 .name 类,粗体是 .title 类):
时,其每个
name1 title1
姓名2 标题2
name3 title3 <~鼠标悬停
name4 title4
当您鼠标移开时,它会返回。
此外,当您单击其中一个
最后,当页面首次加载时,第一个
必须是选定的,如下所示:name1 标题1
姓名2 标题2
姓名3 标题3
name4 title4
我只能完成其中一个功能,比如 click,但不能完成所有 3 个功能。我是 jQuery 新手,所以像这样的多个功能让我的大脑陷入混乱。
如果有任何帮助让我朝着正确的方向前进,我将不胜感激。
I have a list of <ul>
containing 2 <li>
like this:
HTML:
<div id="list">
<ul>
<li>name1</li>
<li>title1</li>
</ul>
<ul>
<li>name2</li>
<li>title2</li>
</ul>
<ul>
<li>name3</li>
<li>title3</li>
</ul>
<ul>
<li>name4</li>
<li>title4</li>
</ul>
and so on...
</div>
CSS:
#list {color: grey}
.name {color: black}
.title {color: red}
Output looks like this (text is all grey):
name1 title1
name2 title2
name3 title3
name4 title4
When you mouseover any of the <ul>
, each of its <li>
gets a class applied to look like this (italics are the .name class, bold is the .title class):
name1 title1
name2 title2
name3 title3 <~the mouseover
name4 title4
When you mouseout, it goes back.
Additionally, when you click on one of the <ul>
it will stay in the styling of the mouseover state and trigger an <a href="something">
And, finally, when the page is first loaded, the first <ul>
has to be the selected one like this:
name1 title1
name2 title2
name3 title3
name4 title4
I have been able to accomplish just one of the functions, say click, but not all 3. I'm new to jQuery, so multiple functions like this send my brain into a spin.
I would be grateful with any help putting me in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面应该做到这一点。如果您打算在其中添加
标记,可能需要进行一些小的调整,但是使用提供的 HTML 结构,这应该可以实现您正在寻找的内容。
和 CSS:
工作示例。
The following should do it. Might need to make small adjustments if you intend to add
<a>
tags in there, but with the provided HTML structure this should accomplish what you are looking for.and the CSS:
Working example.
感谢您对 Niklas 的帮助。
第一个
仍处于“鼠标悬停”状态,因此我将代码修改为如下所示,并且一切正常!
没有你我不可能做到这一点。
Thanks for all of your help Niklas.
The first
<ul>
remained in the "mouseover" state, so I modified the code to look like this and it all works!I couldn't have done it without you.