jquery find() 按类图像
我想找一张他的班级的照片。
我的代码是这样的:
<ul>
<li id='element_1'> <img src="images_1.png" class="image_off"/></li>
<li id='element_2'> <img src="images_2.png" class="image_off"/></li>
</ul>
现在,当我的鼠标位于 LI 或 LI 上时,我想选择内部图像。
我的 jquery 是这样的:
$("li").hover(
var immagine = "img"
ii= jQuery(this).find(immagine);
$(ii).stop().animate({"opacity": "0"}, 500);
}
这工作正常。但是,如果我在同一个 LI 内有 2 个图像,并且我尝试使用他的类来选择图像:
var immagine = "img.image_off"
它不起作用......
你能帮助我吗?
I would like to find an image by his class.
My code is like this:
<ul>
<li id='element_1'> <img src="images_1.png" class="image_off"/></li>
<li id='element_2'> <img src="images_2.png" class="image_off"/></li>
</ul>
Now when my mouse will be orver th LI I would like to select the inner image.
My jquery is like:
$("li").hover(
var immagine = "img"
ii= jQuery(this).find(immagine);
$(ii).stop().animate({"opacity": "0"}, 500);
}
This is workin fine. But if I have 2 images innner the same LI and I try to select the image by his class using:
var immagine = "img.image_off"
it is not working....
Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来你的范例有点混乱!
首先,您应该将一个函数传递给悬停方法。每次您悬停时都会运行该函数。
在悬停方法内,您可以通过传入选择器和上下文来进行上下文搜索。在这种情况下,
this
将代表您将鼠标悬停在其上的li
。这会识别您想要进行手术的每个孩子。
这应该可以满足您的需要:
Looks like you have your paradigms a bit mixed up here!
First off, you should be passing a function to the hover method. That will run the function each time you hover.
Inside the hover method you can then do a contextual search by passing in a selector and a context. In this case
this
will represent theli
that you hovered over.This identifies each of the children you want to operate on.
This should do what you need: