配列をループしてから、リストをループしようとしています。
私が抱えている問題は<li>
、配列全体が追加されるたびに発生することですが、必要なのは、配列のインデックス(0)が最初のliに追加され、index(1)が2番目のliに追加されるなどです。
コード:
// Create our test array.
var arrValues = [ "one", "two", "three" ];
// Loop over each value in the array.
$.each(arrValues,function( intIndex, objValue ){
$("#list span").each(function() {
$(this).append(objValue);
});
});
現在の出力:
<ul id="list">
<li>Content 1 here<span>onetwothree</span></li>
<li>Content 2 here<span>onetwothree</span></li>
<li>Content 3 here<span>onetwothree</span></li>
</ul>
必要な出力:
<ul id="list">
<li>Content 1 here<span>one</span></li>
<li>Content 2 here<span>two</span></li>
<li>Content 3 here<span>three</span></li>
</ul>
どんな助けにも感謝します:)