如果我有一个页面上的5张图像中选择特定的元素,它们都是完全一样的形象,看到下面使用jQuery ATTR()方法
<body>
<img src="http://httpJunkie.com/1st/jQ02/orangeCat.jpg" >
<img src="http://httpJunkie.com/1st/jQ02/orangeCat.jpg" >
<img src="http://httpJunkie.com/1st/jQ02/orangeCat.jpg" >
<img src="http://httpJunkie.com/1st/jQ02/orangeCat.jpg" >
<img src="http://httpJunkie.com/1st/jQ02/orangeCat.jpg" >
</body>
我对它们的访问只能使用JavaScript,我需要使用jQuery修改每个人的高度。假设第一个图像需要为10px x 10px
,并且每个连续图像需要按比例放大10px
。我知道我可以选择使用第一种:
$("body img:first").attr({
width: 10,
height: 10,
});
,并通过使用
$("body img:last").attr({
width: 60,
height: 60,
});
我的主要问题是如何通过使用.attr选择图像数字3()方法中的最后一个,类似于上面的代码
我试过使用nth-child,它没有工作。
P.S:我知道我可以使用一个循环来一次改变它们吗?
[EQ](http://api.jquery.com/eq/),[:EQ](http://api.jquery.com/eq-selector/) ,[gt](http://api.jquery.com/gt-selector/),[lt](http://api.jquery.com/lt-selector/),[n-child](http:/ /api.jquery.com/nth-child-selector/),[第n类型](http://api.jquery.com/nth-of-type-selector/),[第n个最后一个孩子] (http://api.jquery.com/nth-last-child-selector/)。 - > [** https://learn.jquery.com/**](https://learn.jquery.com/) – adeneo
我从学习中心来到这里,因为我在使用第n个孩子时遇到问题。我仍然无法获得第n个孩子的例子。但eq()例子工作正常。有什么不同? –