jquery 选择器:我单击的位置内的引用类:
我有这个 html:
<div class="title"><img class="arrow" src="rightarrow.gif" />Title</div>
我有这个点击事件:
$(document).ready(function () {
$('.title').live('click', function () {
//NEED SOMETHING HERE TO CHANGE SOURCE
$(".arrow").attr("src", "downarrow.gif");
});
});
如您所见,我想更改图像的 src 属性。我上面的选择器可以工作,但是页面上还有其他带有 class ="arrow" 的项目,所以我需要一种方法来仅选择这个实例。
i have this html:
<div class="title"><img class="arrow" src="rightarrow.gif" />Title</div>
i have this click event:
$(document).ready(function () {
$('.title').live('click', function () {
//NEED SOMETHING HERE TO CHANGE SOURCE
$(".arrow").attr("src", "downarrow.gif");
});
});
as you can see i want to change the src attribute of the image. my selector above works, but there are other items on the page with class ="arrow", so i need a way to just select this one instance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
.find()
来限制选择器仅查找包含在被点击的元素(由$(this)
表示):Use
.find()
to constrain the selector to only find elements contained within the element that was clicked (represented by$(this)
):替换为:
$(".arrow").attr({"src": "downarrow.gif"});
Replace with this:
$(".arrow").attr({"src": "downarrow.gif"});