簡體   English   中英

使用jQuery將表頭的值分配給相應的列

[英]Assign the value of table header to corresponding columns using jquery

是否可以使用jQuery / JavaScript將標頭列的值/文本分配給其對應的數據列記錄?

像id列應具有id標頭值,而英語列應具有英文標頭值等。

在此處輸入圖片說明

這是您的解決方案:

       $(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);
            });
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM