jquery - 如果“活动”类在前面,则将“活动”类添加到 TD
问题描述
我不怎么做 jQuery,所以这对其他人来说可能很容易。我有一系列的桌子。有些需要有一个特定的列才能激活。我现在的问题显然是所有表格下面的代码都突出显示了特定$indexNum
值并添加了活动类。
我需要说。th
“您是否在其中一个标签上找到了活动类thead
?”
是的,比在此特定表中查找所有 td 并将活动类应用于与您在 thead 中找到的列相同的列。
不,那么不要对这张桌子做任何事情。
这是我到目前为止所拥有的:
var $indexNum = $('thead tr th.active').index();
$('td:nth-child('+($indexNum+1)+')').addClass('active');
解决方案
我认为这样的事情可以完成这项工作:
$('table th.active').each(function () {
var index = $(this).index()
$(this).parents('table').find('td:nth-child(' + (index + 1) + ')').addClass('active')
})
推荐阅读
- reactjs - 有效的 CSS 未在 React Native WebView 的 HTML 中应用
- regex - firebase.json 中的正则表达式重写
- json - 使用方括号和jsx遍历json
- c# - DocumentClient.CreateDocumentQuery 在运行查询时引发“不是实例”错误
- java - ID 为 URL 时的 API REST
- python - OpenCV 断言失败:(-215:断言失败)npoints >= 0 &&(深度 == CV_32F || 深度 == CV_32S)
- php - 如何将 PHP shell_exec 的响应输出到 HTML 表中?
- android-studio - android studio在构建签名apk时不允许我尝试不同的别名
- python - n维数组中唯一值的索引
- javascript - 以下构造在javascript中是什么意思