0
我有一個以上的data-tablet-src
更多正如你看到的,我想用鍵和值,例如像這樣一一列舉:獲取特定數據的所有值屬性
data-tablet-src => https://unsplash.it/1000/300?image=21
data-tablet-src => https://unsplash.it/1000/300?image=1001
bla...bla..bla...
$(document).ready(function(){
$('#mycarousel .item img[data-tablet-src]').each(function (index, value) {
alert("index:" + index+"value: "+value);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="https://unsplash.it/1000/300?image=68" data-tablet-src="https://unsplash.it/1000/300?image=21">
</div>
<div class="item">
<img src="https://unsplash.it/1000/300?image=43" data-tablet-src="https://unsplash.it/1000/300?image=1001">
</div>
<div class="item">
<img src="https://unsplash.it/1000/300?image=67" data-tablet-src="https://unsplash.it/1000/300?image=1002">
</div>
<div class="item">
<img src="https://unsplash.it/1000/300?image=47" data-tablet-src="https://unsplash.it/1000/300?image=1005">
</div>
<div class="item">
<img src="https://unsplash.it/1000/300?image=72" data-tablet-src="https://unsplash.it/1000/300?image=63">
</div>
</div>
adeneo感謝我對jQuery的新,所以我有一個問題我怎麼能與指數和價值分割? –
不知道你是什麼意思?這只是創建了數組中的值,從第一個元素的數據值將只是'源[0]'等 – adeneo
我的意思是我想列出他們在li元素 –