아래 JS와 기존 범주 세트를 기반으로 탭 세트를 작성하고 있습니다. JS 배열의 값에 따라 DIV id 내 특정 ID를 대상으로 지정해야합니다.배열 내의 값을 기준으로 각 div를 확인하십시오.
$("#categories div[id^=category]:not(:first)", this).hide();
var cats = $('#categories div[id^=category]');
cats.each(function() {
var anch = $(this).find('h3 a').eq(1).clone();
anch[0].rel = this.id;
$('<li/>').append(anch).appendTo('#tabs');
});
HTML : 내가 추가하여 준비 JS 배열을 가지고
<div id="category_1">
<h3 class="maintitle">
<a class="toggle">..</a>
<a href="#">Cat 1 Title</a>
</h3>
<div>
...
</div>
</div>
<div id="category_2">
<h3 class="maintitle">
<a class="toggle">..</a>
<a href="#">Cat 2 Title</a>
</h3>
<div>
...
</div>
</div>
:
var catsList = '{$cats}'; // comma separated list of numbers generated in PHP - returns 1,4,8 currently.
var catsArray = catsList.split(',');
어떻게 catsArray 내에서 각 항목을 확인하려면 아래의 변환 것 ?
var cats = $('#categories div[id^=category]');
뭔가
var cats = $('#categories div[id^=category_'+catsArray+']');
하지만 분명히 각 배열 내에서 항목과 전체 배열을하고있어하지를 확인
있다.
대단한 답변입니다. 완벽하게 작동합니다. 감사! – tctc91