jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 制作第一行的固定标题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Demo
<div id="divScroll" style="overflow-x: hidden">
    <table id="tableAppointment" bgcolor="#fcfcfc" border="1" cellspacing="1" width="100%">

            <tr>
                <td class="csstextheader" width="70px"></td>
                <td class="csstextheader" width="70px">
                    <b>Time Slot&nbsp;</b>
                </td>
                <td><b>Room 7</b></td>
                <td><b>Room 8</b></td>
                <td><b>Room 9</b></td>
                <td><b>Room 10</b></td>
            </tr>



            <tr class="csstablelisttd">
                <td width="70px">08:00AM</td>
                <td>00</td>
                <td class="csstdred">John</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>                                     
            </tr>
    </table>
</div>

在窗口上调用onload

function resolutionIndependent()
        {
            var height;
            var tableMain;
            var divScroll;

            if (document.body && document.body.offsetWidth)
            {
                height = document.body.offsetHeight;
            }
            if (document.compatMode == 'CSS1Compat' && document.documentElement && document.documentElement.offsetWidth)
            {
                height = document.documentElement.offsetHeight;
            }
            if (window.innerWidth && window.innerHeight)
            {
                height = window.innerHeight;
            }
            tableMain = document.getElementById('tableMain');
            divScroll = document.getElementById('divScroll');
            tableMain.style.height = parseFloat(height - 170) + 'px';
            divScroll.style.height = parseFloat(height - 170) + 'px';
            divScroll.style.overflow = "auto";
        }
 //***tableMain which is outer table of divScroll***

我必须制作第一行的固定标题..
我将style =“position:fixed”添加到第一行的每个单元格.但没有得到输出
..怎么可能

解决方法

嘿,你甚至可以使用一个简单的jquery函数,它可以在不改变你的HTML代码的情况下为你提供结果
var tdWidth = $("#tableAppointment tbody tr td").width();
$("#tableAppointment thead").css({'position': 'fixed','top': '0','left': '-0.2%','BACkground-color': '#f94d4d','color': '#FFFFFF','text-align': 'center','width': '100%'});

$("#tableAppointment thead tr th").width(tdWidth);

工作示例是jsfiddle

大佬总结

以上是大佬教程为你收集整理的jquery – 制作第一行的固定标题全部内容,希望文章能够帮你解决jquery – 制作第一行的固定标题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。