【发布时间】:2020-03-12 20:53:46
【问题描述】:
我正在做一个大厅。大厅将包含游戏列表。显示在<table>。每个<tr> 都包含<td> 中的名称、玩家数量等。现在我希望当我单击该行时应显示游戏的相应详细信息。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" />
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
<button class="btn btn-primary">Button</button>
<table class="table text-align=">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr data-toggle="collapse" data-target="#game-1">
<td>Game 1</td>
<div class="collapse" id="game-1">Description of game 2</div>
</tr>
<tr data-toggle="collapse" data-target="#game-2">
<td>Game 2</td>
<div class="collapse" id="game-2">Description of game 2</div>
</tr>
</tbody>
</table>
我尝试在<tr> 中使用<div>。但这并没有很好地工作,并且它在表格之外显示了细节。
- 我想让详细信息显示在行之后。
- 我的第二个问题是,一次只显示一个细节的最佳方式是什么。
注意:我知道我可以在该行之后添加另一行,但这会破坏我的表格结构。所以我不想那样做。
【问题讨论】:
-
使用
div作为表行的兄弟是无效的。您需要添加另一个表格单元或表格行来实现您想要的。或者你需要考虑一个完整的其他结构,例如一个列表 -
如果您的设计允许,您可以使用模态框
-
@LinkinTED 列表的问题是所有列都不会对齐
-
将你的
div标签移动到td标签表中,它就可以正常工作了。 JsFiddle Demo -
对于这个表行为,您可以查看我最近被否决的问题:stackoverflow.com/questions/58492850/…
标签: javascript html css bootstrap-4