我希望将一个数组传递给一个函数(你能告诉我这样做是否正确吗?),然后在函数中,我希望循环遍历数组中的值,并将每个值附加到以下HTML中的LI元素中。这是我目前的代码:用户将编写他想要传递的URL值。
var arrValues = ['http://imgur.com/gallery/L4CmrUt', 'http://imgur.com/gallery/VQEsGHz'];
calculate_image(arrValues);
function calculate_image(arrValues) {
// Loop over each value in the array.
var jList = $('.thumb').find('href');
$.each(arrValues, function(intIndex, objValue) {
// Create a new LI HTML element out of the
// current value (in the iteration) and then
// add this value to the list.
jList.append($(+ objValue +));
});
}
}
HTML
<li>
<a class="thumb" href="" title="Title #13"><img src="" alt="Title #13" /></a>
<div class="caption">
<div class="download">
<a href="">Download Original</a>
</div>
<div class="image-title">Title #13</div>
<div class="image-desc">Description</div>
</div>
</li>