문제

I am using the caroufredsel and add the carousel's elements via html:

<ul>
  <li> element 1 </li>
  <li> element 2 </li>
  <li> ... </li>
</ul>

What I wanted to do now ist not to hardcode the elements in html, instead I want the caroufredsel read the items from an javascript array.

Is this possible?

도움이 되었습니까?

해결책

You can use $.each() to loop through the array and append the variable to the ul:

$(document).ready(function() {
    var testArr = ["element 1","element 2","element 3","element 4"];
    var listItem ="";
    $.each(testArr, function(i, val) {
         listItem += "<li>" + val + "</li>";
    });

    $('#myUL').html(listItem);
});

Demo

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top