我正在申请预订房间,我使用 Angular 2。我想在我的表格中选择单元格并获取垂直和水平标题的值,如“房间 1”和“9:00”。我正在从服务器获取表标题的数据。这是我的 html 代码:
<div class="table">
<table class="schedule-table" *ngIf="titles && titles.length && intervals && intervals.length">
<tr>
<th class="vertical-header-cell"></th>
<th class="horizontal-header-cell" *ngFor="let title of titles">{{ title }}</th>
</tr>
<tr *ngFor="let interval of intervals">
<th class="vertical-header-cell">{{ interval }}</th>
<th class="body-cell" *ngFor="let title of titles"></th>
</tr>
</table>
我的CSS:
table {
width: 100%;
margin-top: 100px;
border-collapse: collapse;
}
th {
height: 60px;
}
table, th, td {
border: 1px solid black;
}
.body-cell:hover{
background-color: green;
}
.vertical-header-cell {
width: 100px;
}
使用click
函数
<th class="horizontal-header-cell" *ngFor="let title of titles" (click)="clickHeader(title,intervals)" >{{ title }}</th>
clickHeader(title: any, intervals: any){
console.log(title + intervals)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句