如果我有一個頁面上的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()例子工作正常。有什麼不同? –