查找父兄弟td隐藏值
Find parent sibling td hidden value
当单击div.中的correct尝试类时,我想找到父兄弟td隐藏值
<tr th:each="m : ${markWiseResultModel}">
<td th:text="${m.id}" align="center"></td>
<td class="topicTD">
<input type="hidden" class="topicId" th:value="${m.topic.id}"/>
<div th:text="${m.topic.name}" align="center"></div>
</td>
<td data-toggle="modal" style="background:#b8d1f3;">
<div class="correctAttempt" th:text="${m.correctAttemptCount}" align="center" ></div>
</td>
<td th:text="${m.correctAttemptPercent}" align="center" style="background:#99FF99;"></td>
<td th:text="${m.wrongAttemptCount}" align="center" style="background:#b8d1f3;"></td>
<td th:text="${m.wrongAttemptPercent}" align="center" style="background:#99FF99;"></td>
<td th:text="${m.correctTotalCount}" align="center" style="background:#b8d1f3;"></td>
<td th:text="${m.correctTotalPercent}" align="center" style="background:#99FF99;"></td>
<td th:text="${m.wrongTotalCount}" align="center" style="background:#b8d1f3;"></td>
<td th:text="${m.wrongTotalPercent}" align="center" style="background:#99FF99;"></td>
</tr>
<script>
$(document).ready(function(){
$('.correctAttempt').click(function(){
var id = $(this).parents('td').siblings('.topicTD').find(".topicId").val();
alert(id);
$('#correctOutOfAttempt').modal('show');
});
});
</script>
已经尝试过脚本,但没有成功。
试试这个-
演示
$(document).ready(function(){
$('.correctAttempt').click(function(){
var id= $(this).parent().prev('.topicTD').find(".topicId").val();
alert(id);
$('#correctOutOfAttempt').modal('show');
});
});
试试这个。
<script>
$(document).ready(function(){
$('.correctAttempt').click(function(){
var id= $(this).parent().prev('.topicTD').find(".topicId").val();
alert(id);
$('#correctOutOfAttempt').modal('show');
});
});
</script>
您可以使用closest
来获取父tr
元素,然后您需要找到.topicId
。试试这个:
<script>
$(document).ready(function(){
$('.correctAttempt').click(function(){
var id = $(this).closest('tr').find(".topicId").val();
alert(id);
$('#correctOutOfAttempt').modal('show');
});
});
</script>
使用closest
而不是严格按父级遍历的优点是,只要类名保持不变,就可以更改tr
和td
结构,而不必修改JS代码。
小提琴示例
相关文章:
- JQuery展开和隐藏表td
- 在td JavaScript中获取隐藏的输入值
- 防止隐藏的 tr 破坏 td 宽度
- 根据TD类别隐藏TR
- jQuery隐藏所有trs或td,而不仅仅是一个
- 如果包含完全匹配,则隐藏表td
- AngularJS:隐藏<td>使用ng-hide/ng-show没有间隙
- 使用jquery隐藏td
- 使用 jQuery 不检查隐藏的 td:s
- 当鼠标悬停在TD上时,保持标题向上,并将其隐藏在鼠标上
- 选择任何 TR 和/或 TD 并隐藏元素
- 在 jquery 中显示和隐藏 td
- 如何通过jquery从td隐藏字段中获取值
- 如何使用JQuery基于存储在第一个TD中的表的值来隐藏存储在第二个TD的图像
- 删除/隐藏表<tr>(s) 其<td>(s) 没有文本
- 隐藏<td>AJAX刷新后从表中删除
- 查找父兄弟td隐藏值
- html嵌套表通过单击表行第一个td来隐藏或显示表行
- 仅当td在特定html标记后不包含任何内容时,才隐藏tr
- 如何在PHP编码器中动态获取数据时隐藏td