IMG SRC我有簡單的HTML看起來像這樣:jQuery的如何選擇內HREF
<div class="img">
<a target="_blank" href="kl_big.htm" id="turn-of-cloth-01_lg">
<img src="images/galery/turn-of-cloth-01_lg.jpg" width="110" height="90" />
</a>
<div class="desc">Add a description of the image here</div>
</div>
我有像20套該div有不同的ID,現在在href ID IM與此
gtting$(document).ready(function(){
$('a').click(function (event){
event.preventDefault();
var linkID =$(this).attr("id");
});
});
我不知道什麼是img對象id,但我需要獲取它的src值。 我試圖用jQuery這樣的:
var imgSrcVal = $(this).siblings("img").attr("src");
但出來的結果,也tryied click事件內,但再次沒有結果:
imgSrcVal = this.nextSibling.src;
錯在這裏做什麼IM?
你試圖讓孩子圖像(標籤內)?在這種情況下,你不應該使用「兄弟姐妹」,而是「孩子」。 – EdMelo