Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 响应表:显示AD元素';相应tds中的内容_Jquery_Css_Media Queries_Col - Fatal编程技术网

Jquery 响应表:显示AD元素';相应tds中的内容

Jquery 响应表:显示AD元素';相应tds中的内容,jquery,css,media-queries,col,Jquery,Css,Media Queries,Col,我有类似于此简化版本的表格: <table> <thead> <tr><th></th> <th>1st sg.</th><th>2nd</th><th>3rd...</th> </tr> </thead> <tbody> <tr

我有类似于此简化版本的表格:

<table>
    <thead>
        <tr><th></th>
            <th>1st sg.</th><th>2nd</th><th>3rd...</th>
        </tr>
    </thead>
    <tbody>
        <tr><th>Present</th>
            <td>sum</td><td>es</td><td>est...</td>
        </tr>
        <tr><th>Perfect</th>
            <td>fui</td><td>fuisti</td><td>fuit...</td>
        </tr>
    </tbody>
</table>
因此,我的技术问题如下:

<tbody>
    <tr>
        <th>Present</th>
        <td data-col="1st sg.">sum</td>
        <td data-col="2nd">es</td>
        <td data-col="3rd">est</td>
    </tr>
</tbody>
如何动态地从thead的th元素获取内容,并将所述内容作为属性分发到同一列的所有tds?


其他解决方案也很受欢迎

这里是一个javascript函数。看看这是否有帮助

    function td_col()
    {
        var table = $('table');
        table.find('tbody tr').each(function(){
            $(this).find('td').each(function(i){ 
               $(this).attr('data-col', table.find('thead tr th:eq('+(i + 1)+')').html());
            })
        })
    }
CSS更新:

        @media(max-width:470px) {
        td:before {
            float:right;
            content:attr(data-col); //Removed the brackets.
        }
    }

我没有理解你的问题,你说的“将其作为属性分发回所有相应的tds”是什么意思?对不起,我的英语不完美^我的意思类似于ad:Th(1):content=>Tbody:Tr(a):Td(1):attribute,Tbody:Tr(b):Td(1):attribute等等。好的,但请尝试解释一下你到底想做什么?通过给定的代码示例进行解释。这里是
1st sg.
你们想放在桌子上的什么地方?我爱你们!那是难以置信的快,你的秘诀是什么?没什么,只是多喝水:这就是我整天做的事——喝水——哦。但真的非常感谢!哦,这是一个小问题,当页面上有多个表时,它会将相同的属性从第一个thead传递给下面的表…在函数中传递一个参数,即表的id或实例。