使用jquery将表头的值分配给相应的列

时间:2017-09-18 12:22:21

标签: javascript jquery

是否可以使用jQuery / JavaScript将header列的值/文本分配给相应的数据列记录?

像 id列应具有id标头值,英文列应具有英文标题值等。

enter image description here

1 个答案:

答案 0 :(得分:1)

这是你的解决方案:

       $(document).ready(function(){
            $('tr').find('td').each(function(i){
                var ind = $(this).index();
                var text = $(this).text();
                var header_text = $('thead > tr').find('th:eq('+ind+')').text();
                $(this).text(header_text+': '+text);
            });
        });