我試圖找到我的div如何找到某個元素在div內的位置?
我的HTML內的圖像位置
<div>
<p>test</p>
<img src='test1.jpg'/>
<p>test</p>
<p>test</p>
<img src='test2.jpg'/>
<p>test</p>
<img src='test2.jpg'/> --the user clicks this image and I want to know the time it appears. In this case, 2 is what I need.
<p>test</p>
<img src='test2.jpg'/>
<p>test</p>
</div>
我
var imagePosition=0;
$('img').click(function(){
var imgSource=$(this).attr('src');
$(this).closest('div').find('img').each(function(){
if($(this).attr('src')==imgSource){
imagePosition++;
}
})
})
我可以找出相同的圖像多少時間出現,但我可以」告訴用戶點擊哪個圖像,並確定其位置。有沒有辦法做到這一點?非常感謝!
你的意思是不是'this.offsetLeft'和'this.offsetTop'其他? – 2013-02-13 04:02:55
所以如果有人點擊div,你想要的輸出是什麼? img的src屬性? – kinakuta 2013-02-13 04:07:27