같은 여러 개를 가질 수 있습니까?
<tbody>
동일한 태그를 여러 개 가질 수 있습니까 <table>
? 그렇다면 어떤 시나리오에서 여러 <tbody>
태그를 사용해야 합니까?
예, 사용할 수 있습니다. 예를 들어 다음과 같이 데이터 그룹을보다 쉽게 스타일링하는 데 사용합니다.
thead th { width: 100px; border-bottom: solid 1px #ddd; font-weight: bold; }
tbody:nth-child(odd) { background: #f5f5f5; border: solid 1px #ddd; }
tbody:nth-child(even) { background: #e5e5e5; border: solid 1px #ddd; }
<table>
<thead>
<tr><th>Customer</th><th>Order</th><th>Month</th></tr>
</thead>
<tbody>
<tr><td>Customer 1</td><td>#1</td><td>January</td></tr>
<tr><td>Customer 1</td><td>#2</td><td>April</td></tr>
<tr><td>Customer 1</td><td>#3</td><td>March</td></tr>
</tbody>
<tbody>
<tr><td>Customer 2</td><td>#1</td><td>January</td></tr>
<tr><td>Customer 2</td><td>#2</td><td>April</td></tr>
<tr><td>Customer 2</td><td>#3</td><td>March</td></tr>
</tbody>
<tbody>
<tr><td>Customer 3</td><td>#1</td><td>January</td></tr>
<tr><td>Customer 3</td><td>#2</td><td>April</td></tr>
<tr><td>Customer 3</td><td>#3</td><td>March</td></tr>
</tbody>
</table>
여기에서 예를 볼 수 있습니다 . 최신 브라우저에서만 작동하지만 현재 애플리케이션에서 지원하는 것입니다. JavaScript 등에 대한 그룹화를 사용할 수 있습니다. 중요한 것은 데이터를 훨씬 더 읽기 쉽게 만들기 위해 행을 시각적으로 그룹화하는 편리한 방법이라는 것입니다. . 물론 다른 용도가 있지만 적용 가능한 예에서는 이것이 가장 일반적인 용도입니다.
예. 에서 DTD를
<!ELEMENT table
(caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))>
따라서 하나 이상을 예상합니다. 그런 다음 계속해서
테이블 행 그룹간에 규칙 이 필요한 경우 여러 tbody 섹션을 사용하십시오 .
이 예제에 따르면 할 수 있습니다 : w3-struct-tables .
Martin Joiner의 문제는 <caption>
태그 에 대한 오해로 인해 발생합니다 .
<caption>
태그는 테이블의 캡션을 정의합니다.
<caption>
태그의 첫 번째 자식이어야 <table>
태그입니다.
테이블 당 하나의 캡션 만 지정할 수 있습니다.
또한 scope
속성은 <th>
요소가 아닌 요소에 배치되어야합니다 <tr>
.
다중 헤더 다중 tbody 테이블을 작성하는 적절한 방법은 다음과 같습니다.
<table id="dinner_table">
<caption>This is the only correct place to put a caption.</caption>
<tbody>
<tr class="header">
<th colspan="2" scope="col">First Half of Table (British Dinner)</th>
</tr>
<tr>
<th scope="row">1</th>
<td>Fish</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Chips</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Peas</td>
</tr>
<tr>
<th scope="row">4</th>
<td>Gravy</td>
</tr>
</tbody>
<tbody>
<tr class="header">
<th colspan="2" scope="col">Second Half of Table (Italian Dinner)</th>
</tr>
<tr>
<th scope="row">5</th>
<td>Pizza</td>
</tr>
<tr>
<th scope="row">6</th>
<td>Salad</td>
</tr>
<tr>
<th scope="row">7</th>
<td>Oil</td>
</tr>
<tr>
<th scope="row">8</th>
<td>Bread</td>
</tr>
</tbody>
</table>
예. 나는 코스와 같은 테이블의 관련 부분을 동적으로 숨기거나 드러내는 데 사용합니다. 즉.
<table>
<tbody id="day1" style="display:none">
<tr><td>session1</td><tr>
<tr><td>session2</td><tr>
</tbody>
<tbody id="day2">
<tr><td>session3</td><tr>
<tr><td>session4</td><tr>
</tbody>
<tbody id="day3" style="display:none">
<tr><td>session5</td><tr>
<tr><td>session6</td><tr>
</tbody>
</table>
A button can be provided to toggle between everything or just the current day by manipulating tbodies without processing many rows individually.
EDIT: The caption
tag belongs to table and thus should only exist once. Do not associate a caption
with each tbody
element like I did:
<table>
<caption>First Half of Table (British Dinner)</caption>
<tbody>
<tr><th>1</th><td>Fish</td></tr>
<tr><th>2</th><td>Chips</td></tr>
<tr><th>3</th><td>Pease</td></tr>
<tr><th>4</th><td>Gravy</td></tr>
</tbody>
<caption>Second Half of Table (Italian Dinner)</caption>
<tbody>
<tr><th>5</th><td>Pizza</td></tr>
<tr><th>6</th><td>Salad</td></tr>
<tr><th>7</th><td>Oil</td></tr>
<tr><th>8</th><td>Bread</td></tr>
</tbody>
</table>
BAD EXAMPLE ABOVE: DO NOT COPY
The above example does not render as you would expect because writing like this indicates a misunderstanding of the caption
tag. You would need lots of CSS hacks to make it render correctly because you would be going against standards.
I searched for W3Cs standards on the caption
tag but could not find an explicit rule that states there must be only one caption
element per table but that is in fact the case.
In addition, if you run a HTML document with multiple <tbody>
tags through W3C's HTML Validator, with a HTML5 DOCTYPE, it will successfully validate.
I have created a JSFiddle where I have two nested ng-repeats with tables, and the parent ng-repeat on tbody. If you inspect any row in the table, you will see there are six tbody elements, i.e. the parent level.
HTML
<div>
<table class="table table-hover table-condensed table-striped">
<thead>
<tr>
<th>Store ID</th>
<th>Name</th>
<th>Address</th>
<th>City</th>
<th>Cost</th>
<th>Sales</th>
<th>Revenue</th>
<th>Employees</th>
<th>Employees H-sum</th>
</tr>
</thead>
<tbody data-ng-repeat="storedata in storeDataModel.storedata">
<tr id="storedata.store.storeId" class="clickableRow" title="Click to toggle collapse/expand day summaries for this store." data-ng-click="selectTableRow($index, storedata.store.storeId)">
<td>{{storedata.store.storeId}}</td>
<td>{{storedata.store.storeName}}</td>
<td>{{storedata.store.storeAddress}}</td>
<td>{{storedata.store.storeCity}}</td>
<td>{{storedata.data.costTotal}}</td>
<td>{{storedata.data.salesTotal}}</td>
<td>{{storedata.data.revenueTotal}}</td>
<td>{{storedata.data.averageEmployees}}</td>
<td>{{storedata.data.averageEmployeesHours}}</td>
</tr>
<tr data-ng-show="dayDataCollapse[$index]">
<td colspan="2"> </td>
<td colspan="7">
<div>
<div class="pull-right">
<table class="table table-hover table-condensed table-striped">
<thead>
<tr>
<th></th>
<th>Date [YYYY-MM-dd]</th>
<th>Cost</th>
<th>Sales</th>
<th>Revenue</th>
<th>Employees</th>
<th>Employees H-sum</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="dayData in storeDataModel.storedata[$index].data.dayData">
<td class="pullright">
<button type="btn btn-small" title="Click to show transactions for this specific day..." data-ng-click=""><i class="icon-list"></i>
</button>
</td>
<td>{{dayData.date}}</td>
<td>{{dayData.cost}}</td>
<td>{{dayData.sales}}</td>
<td>{{dayData.revenue}}</td>
<td>{{dayData.employees}}</td>
<td>{{dayData.employeesHoursSum}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
( Side note: This fills up the DOM if you have a lot of data on both levels, so I am therefore working on a directive to fetch data and replace, i.e. adding into DOM when clicking parent and removing when another is clicked or same parent again. To get the kind of behavior you find on Prisjakt.nu, if you scroll down to the computers listed and click on the row (not the links). If you do that and inspect elements you will see that a tr is added and then removed if parent is clicked again or another. )
참고URL : https://stackoverflow.com/questions/3076708/can-we-have-multiple-tbody-in-same-table
'code' 카테고리의 다른 글
xcode-select 활성 개발자 디렉토리 오류 (0) | 2020.10.03 |
---|---|
인증 대 권한 부여 (0) | 2020.10.03 |
REST API-실제 사례가 포함 된 PUT 대 PATCH (0) | 2020.10.03 |
grep -R에서 디렉토리를 제외하려면 어떻게해야합니까? (0) | 2020.10.03 |
android : layout_weight는 무엇을 의미합니까? (0) | 2020.10.02 |