如何从数组中获取图像图标&在DIV中逐个追加。我有一个带图像路径的数组。我想从该阵列获取图像&在DIV中逐个追加。
我想在“class = acc_trigger”div中附加这些图标..这里是HTML
<div class="container">
<h2 class="acc_trigger"><a href="#">Home</a></h2>
<div class="acc_container">
<div class="block">
<ul>
<li><a href="#">One</a></li>
<li><a href="#">One</a></li>
<li><a href="#">One</a></li>
</ul>
</div>
</div>
<h2 class="acc_trigger"><a href="#">Req Mgmt</a></h2>
<div class="acc_container">
<div class="block">
<ul>
<li><a href="#">Requirments</a></li>
<li><a href="#">Use Cases</a></li>
<li><a href="#">Test Cases</a></li>
</ul>
</div>
</div>
<h2 class="acc_trigger"><a href="#">Test</a></h2>
<div class="acc_container">
<div class="block">
<ul>
<li><a href="#">One</a></li>
<li><a href="#">One</a></li>
<li><a href="#">One</a></li>
</ul>
</div>
</div>
<h2 class="acc_trigger"><a href="#">Project</a></h2>
<div class="acc_container">
<div class="block">
<ul>
<li><a href="#">One</a></li>
<li><a href="#">One</a></li>
<li><a href="#">One</a></li>
</ul>
</div>
</div>
</div>
*********** JQUERY ARRAY *****************
var $iconLeft = new Array();
$iconLeft[0] = 'images/icons/home_icon.gif';
$iconLeft[1] = 'images/icons/reqMgmt_icon.gif';
$iconLeft[2] = 'images/icons/test_icon.gif';
$iconLeft[3] = 'images/icons/project_icon.gif';
$iconLeft[4] = 'images/icons/issue_icon.gif';
$iconLeft[5] = 'images/icons/more_icon.gif';
我应该使用.each()??如果是的话,该如何使用?请帮忙。
答案 0 :(得分:0)
试试这个:
$(document).ready(function () {
$('h2.acc_trigger').each(function(i){
var icon = new Array;
icon[0] = 'images/icons/home_icon.gif';
icon[1] = 'images/icons/reqMgmt_icon.gif';
icon[2] = 'images/icons/test_icon.gif';
icon[3] = 'images/icons/project_icon.gif';
icon[4] = 'images/icons/issue_icon.gif';
icon[5] = 'images/icons/more_icon.gif';
$(this).prepend('<img src='+icon[i]+' />');
});
});