javascript - 查找父兄弟 td 隐藏值

标签 javascript jquery html

我想在单击 div 中的 CorrectAttempt 类时找到父同级 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>

已经尝试过脚本但没有成功。

最佳答案

试试这个-

Demo

 $(document).ready(function(){
      $('.correctAttempt').click(function(){
        var id=  $(this).parent().prev('.topicTD').find(".topicId").val();
        alert(id);
        $('#correctOutOfAttempt').modal('show');
      });
    });

关于javascript - 查找父兄弟 td 隐藏值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26271996/

相关文章:

javascript - js和jquery的OOP框架

javascript - 抓取数据ID值

javascript - 用于圆形的 HTML5 Canvas ctx.clip() 方法在圆形下方留下一条线

javascript - 加载页面问题

javascript - 如何使用 jQuery 在多级菜单中选择没有 child 的 li?

css - 我听说你喜欢 DIV,所以我把你的 DIV 放在你的 DIV 中

javascript - 选择子菜单后如何使导航栏的主菜单处于事件状态(突出显示)

javascript - 从第 '1' 行的数据源请求未知参数 '0'

javascript - 如何获取地标上点击点的经度、纬度和海拔高度?

javascript - 在 RequireJS 中使用私有(private) jquery - 优化后的问题