0
의 우리가이 미확인 DIV의 jQuery으로 .Append (기능 (인덱스, HTML) {...}) 질문
<div class="class-occurs-many-times-on-page">foo</div>
을 가지고 우리가 바로 후 수십 포함 된 다른 정체 불명의 DIV를 배치 할 가정 해 봅시다 SPAN 요소 또는 수백 :
<div class="a-class-that-occurs-many-times-on-page">foo</div>
<div class="another-class-that-occurs-many-times-on-page">
<span class="latin">lorem</span><span class="latin">ipse</span>
<span class="swedish-chef">føø</span><span class="swedish-chef">bår</span>
.
.
.
<span>...</span>
</div>
우리가 처음 미확인 DIV를 추가하고 이런 식으로 SPAN-컨테이너 DIV를 추가 할 수있다 :
values = [{word: "lorem", cls: "latin"}, {word: "ipse", cls: "latin"},
{word:"føø",cls:"swedish-chef"}, {word:"bår",cls:"swedish-chef"}];
$("#" + someParentElement).append(
$("<div></div>").addClass("a-class-that-occurs-many-times-on-page").text("foo").after(
$("<div></div>").addClass("another-class-that-occurs-many-times-on-page").append(
function(index, html){
// how to wrap each value in the values array in a span
// and inject each of those spans into this DIV?
}
)
)
);
이 접근이 가능합니까? 그렇다면 배열의 각 값을 다음과 같이 배열의 각 줄을 래핑하는 것이면 .append() 메서드 호출 내부의 함수가 값 배열을 반복 할 때마다 수행해야하는 작업은 무엇입니까? 스팬과 스팬을 컨테이너에 주입합니까? 당신은 작업의 종류를 달성 할 수 있었던 것처럼 단지 제안이다
감사
감사합니다, jAndy. 제안은 도움이되지만 $ ctn에 대한 참조를 만들면 질문/문제를 피할 수 있습니다. 연결 방법 만 사용하여이 작업을 수행 할 수 있는지 궁금합니다. – Tim