javascript - 从html数据中获取Column数据

标签 javascript jquery html

我想获取第一个的所有列值。例如在this Fiddle中当我访问 th 时,我想获取该列中的所有 td。

$(document).ready(function(){
$('.tableizer-table th').each(function(index,val){

       $('.tableizer-table tr td').eq(index).each(function (index,value) {
        console.log(value);
       });


  });
  });

以上代码不起作用。

最佳答案

我假设当您悬停或访问列标题时,您希望将该列下的所有 td 元素写入控制台。

$(document).ready(function(){
    $('.tableizer-table th').on('hover', function(){
        var columnIndex = $(this).parent().index($(this));

        $('.tableizer-table tbody tr').each(function() {
            console.log($(this).children('td').eq(columnIndex).text());
        });
    });
});

关于javascript - 从html数据中获取Column数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38253141/

相关文章:

javascript - Angular 路线不起作用并且不改变当前 View

javascript - 为什么 Chrome 的 JS 控制台返回 DOM 元素而不是 jQuery 对象?

javascript - Fancybox: 无法加载请求的内容。请稍后再试

jquery - 当我点击菜单 li 时,菜单未隐藏(jquery)

javascript - document.getElementsByTagName() 会动态变化

javascript - AngularJS html 5 模式

javascript - Draggable & Droppable 问题

javascript - 当有多个同名单选按钮时,如何检查选择了哪个单选按钮? (使用jquery)

javascript - 将 CSS 应用于生成的 href

html - <a> 元素在移除 ALIGN-ITEMS 时填满整行 : CENTER