그래서 사용자가 탭을 추가하고 탭을 제거 할 수있는 무언가가 있습니다. 그러나 SQL의 데이터를 기반으로 기본 탭 수를 생성하는 방법은 무엇입니까? 데이터 베이스. 예를 들어, id 필드에 동일한 id를 가진 4 개의 행이 있다면, 동일한 id를 가진 4 개의 행이 있으므로 4 개의 탭을 생성합니다.특정 수의 탭을 생성하는 행 수를 계산하십시오.
여기는 내가 찾은 탭입니다.
<script>
$(function() {
var total_tabs = 0;
// initialize first tab
total_tabs++;
addtab(total_tabs);
$("#addtab, #litab").click(function() {
total_tabs++;
$("#tabcontent p").hide();
addtab(total_tabs);
return false;
});
function addtab(count) {
var closetab = '<a href="" id="close'+count+'" class="close">×</a>';
$("#tabul").append('<li id="t'+count+'" class="ntabs">Session '+count+' '+closetab+'</li>');
$("#tabcontent").append('<p id="c'+count+'">Tab Content '+count+'</p>');
$("#tabul li").removeClass("ctab");
$("#t"+count).addClass("ctab");
$("#t"+count).bind("click", function() {
$("#tabul li").removeClass("ctab");
$("#t"+count).addClass("ctab");
$("#tabcontent p").hide();
$("#c"+count).fadeIn('slow');
});
$("#close"+count).bind("click", function() {
// activate the previous tab
$("#tabul li").removeClass("ctab");
$("#tabcontent p").hide();
$(this).parent().prev().addClass("ctab");
$("#c"+count).prev().fadeIn('slow');
$(this).parent().remove();
$("#c"+count).remove();
return false;
});
}
});
</script>
<ul id="tabul">
<li id="litab" class="ntabs add"><a href="" id="addtab">Add tab + </a></li>
</ul>
감사 제임스
ID는 고유해야 ** 고유 ** – Andreas
제공된 코드를 기반으로하지 않는 한 js/jquery와 비슷하지만 PHP가 아닙니다. – Class
그래 사실이지만 데이터베이스에 연결 한 후 php/sql이 포함되어 있다고 가정합니다. –