javascript - 表格中的滑动切换冲突
问题描述
我需要在点击表格中的图标时显示一些数据。我的问题是只有第一个 tr 受到影响。
在我的html代码下面
@foreach (var item in Model.Request)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.RequestTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.RequestContent)
</td>
<td>
<a href="#" class="showExtra"><i class="fas fa-plus"></i>
</a>
<a href="#" class="showReplies"><i class="fas fa-info"></i>
</a>
</td>
</tr>
<tr>
<td>
<div class="extra" style="display:none">
extra
</div>
</td>
</tr>
<tr>
<td>
<div class="replies" style="display:none">
<div> replies</div>
</div>
</td>
</tr>
}
还有我的脚本代码
<script>
$(".showReplies").click(function () {
$(this).closest("tr").next("tr").find(".replies").slideToggle("slow");
})
$(".showExtra").click(function () {
$(this).closest("tr").next("tr").find(".extra").slideToggle("slow");
})
</script>
我需要根据相应的点击隐藏/显示每个 tr。任何想法?谢谢!
解决方案
你总是在.extra
寻找.replies
第二<tr>
。更改代码如下。table
而是找到它们。
$(".showReplies").click(function() {
$(this).closest("table").find(".replies").slideToggle("slow");
})
$(".showExtra").click(function() {
$(this).closest("table").find(".extra").slideToggle("slow");
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td>
<a href="#" class="showExtra">Show Extra</a>
<a href="#" class="showReplies">Show Replies</a>
</td>
</tr>
<tr>
<td>
<div class="extra" style="display:none">
extra
</div>
</td>
</tr>
<tr>
<td>
<div class="replies" style="display:none">
<div> replies</div>
</div>
</td>
</tr>
</table>
推荐阅读
- azure - 通过 terraform 一起使用 count 和 for_each 来创建 AKS 附加节点池
- django - 在 django-autocomplete-light 中转发 ManyToMany 模型字段
- jar - 由于我们从 7.21 升级到 Artifactory 7.24.3。我们无法使用 JAR 浏览 jar 文件中的内容!在网址中
- python - PyTorch 的 torch.as_strided 具有负步幅,用于制作 Toeplitz 矩阵
- postgresql - 可以在 postgres 中对默认值使用表达式吗?
- python-xarray - Curvillinear Dataset.swap_dims 或 ncks --rgr 推断坐标变量规范选项
- python - Pandas:根据股票价格获取目标和损失指标,达到一定的比率并动态改变基本价格
- ios - iOS Voice Over 焦点位于 UIWindow 下方
- javascript - 数据表删除导出到 pdf 和 excel 的列
- javascript - 显示在无和块之间切换时的flickity.js画廊重叠文本