ES6單行:
Array.from(document.querySelectorAll('#siteTable > .thing')).map(div => div.getAttribute('data-url'))
var urls =
Array.from(document.querySelectorAll('#siteTable > .thing')).map(div => div.getAttribute('data-url'))
console.log(urls)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="siteTable">
<div class="thing id12" data-url="www.aaax.com"></div>
<div class="thing id23" data-url="www.bcbc.com"></div>
<div class="thing id34" data-url="www.eeed.com"></div>
<div class="thing id45" data-url="www.djhn.com"></div>
<div class="thing id92295" data-url="www.zzzzhn.com"></div>
</div>
jQuery的單行:
$('#siteTable > .thing').map(function() {return $(this).attr('data-url')}).get()
var urls =
$('#siteTable > .thing').map(function() {return $(this).attr('data-url')}).get()
console.log(urls)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="siteTable">
<div class="thing id12" data-url="www.aaax.com"></div>
<div class="thing id23" data-url="www.bcbc.com"></div>
<div class="thing id34" data-url="www.eeed.com"></div>
<div class="thing id45" data-url="www.djhn.com"></div>
<div class="thing id92295" data-url="www.zzzzhn.com"></div>
</div>
你只想把他們都在一個數組或你在找什麼做?你有什麼嘗試?每個(函數(){var $ this = $(this); var url = $ this.attr('data-url')})'' –