将鼠标悬停在另一个 div 上时更改 Div 属性?
所以基本上这就是我将要做的:
<div id="1">
<div id="top"></div>
Text
Text
Text
etc.
<div id="bottom"></div>
</div>
我将如何去做以下事情: 如果有人将鼠标悬停在 div“1”(整个容器 div)上,请更改“底部”div(并且仅该底部 div)的属性,例如添加一个名为“over”的类。
我确信有一种方法,但我猜它需要使用 jquery 之类的东西。
So basically this is what I'm going to have:
<div id="1">
<div id="top"></div>
Text
Text
Text
etc.
<div id="bottom"></div>
</div>
How would I go about doing the following:
If someone hovers over div "1" (the entire container div) change the property of the "bottom" div (and only that bottom div) such as adding a class called "over".
I'm sure there's a way however I'm guessing it would need to use something such as jquery.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你有 jquery,那么它非常简单(这对我有用):
If you have jquery, then it is pretty simple (this worked for me):
首先,不要使用数字作为 div id
First thing is don't use numbers for div ids
是的,你是对的。您将需要一些 jQuery 来完成您想做的事情。
如果您去查看悬停函数,jQuery API 文档中有您正在寻找的确切示例。转到底部查看示例。根据您自己的代码进行调整。
Yes, you are correct. You will need some jQuery to accomplish what you want to do.
The jQuery API documentation has the exact example you are looking for if you go and check out the hover function. Go to the bottom for an example. Adjust for your own code.