• 用2个层来显示 table 第一行 定位 效果。 支持ie6/ie7/ff/chrome,两个方向滚动条 ,保证最后一列也能对齐


    能保持最后一列对齐原理:动态显示header行的最后一个行。

    效果

    Header A Header B Header C Header C
    A B CCC CCC
    A B CCC CCC
    A B CCC CCC
    A B CCC CCC
    A B CCC CCC
    A B CCC CCC
    A B CCC CCC
    A B CCC CCC
    A B CCC CCC

    代码

    <script type="text/javascript">// <![CDATA[
    			   var EventUtil = new Object;
                    EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
                        if (oTarget.addEventListener) {
                            oTarget.addEventListener(sEventType, fnHandler, false);
                        } else if (oTarget.attachEvent) {
                            oTarget.attachEvent("on" + sEventType, fnHandler);
                        } else {
                            oTarget["on" + sEventType] = fnHandler;
                        }
                    };
    
    				var oo = function(){
    					var div = document.getElementById("divContent");
    					var left = div.scrollLeft;
    					var div2 = document.getElementById("divHeader");
    					div2.scrollLeft = left;
    
    					var disWidth = div.children[0].style.width.replace("px","")-div.style.width.replace("px","");
    					if(div.scrollLeft >= disWidth ){
    						var ddd= document.getElementById("lastTd");
    						ddd.width = ddd.clientWidth+19;
    					}
    				}
    
    				window.onload = function() {
                        var oDiv = document.getElementById("divContent");   
                        EventUtil.addEventHandler(oDiv, "scroll", oo);
                    }
    // ]]></script>
    <p> </p>
    <div style="margin-right: auto; margin-left: auto; overflow: auto;" id="div1All">
    <div style="overflow: hidden; margin-right: auto; margin-left: auto;  600px;" id="divHeader">   
         
    <table style="margin-top: -2px;  800px;" border="1" cellspacing="0">
    <tbody>
    <tr id="idTr" style="background: none repeat scroll 0% 0% navy; color: white; height: 30px;" class="fixedHeaderTr">
    <td nowrap="nowrap" width="200">Header   A</td>
    <td nowrap="nowrap" width="100">Header   B</td>
    <td nowrap="nowrap" width="200" >Header   C</td>
    <td nowrap="nowrap"  id="lastTd">Header   C</td>
    </tr>
    </tbody>
    </table>
    </div>
    
    <div style="overflow: auto; margin-right: auto; margin-left: auto; height: 150px;  600px;" id="divContent">   
                
    			
    <table style=" 800px;padding-top:0;border-top- 0;" border="1" cellspacing="0">
    <tbody>
    		<tr>
    			<td width="200">A</td>
    			<td width="100">B</td>
    			<td nowrap="nowrap" width="200">CCC</td>
    			<td nowrap="nowrap" >CCC</td>
    		</tr>
    		<tr>
    		<td >A</td>
    		<td >B</td>
    		<td nowrap="nowrap" >CCC</td>
    		<td nowrap="nowrap" >CCC</td>
    		</tr>
    		<tr>
    		<td >A</td>
    		<td >B</td>
    		<td nowrap="nowrap" >CCC</td>
    		<td nowrap="nowrap" >CCC</td>
    		</tr>
    		<tr>
    					<td >A</td>
    					<td >B</td>
    					<td nowrap="nowrap" >CCC</td>
    					<td nowrap="nowrap" >CCC</td>
    		</tr>
    		<tr>
    				<td >A</td>
    				<td >B</td>
    				<td nowrap="nowrap" >CCC</td>
    				<td nowrap="nowrap" >CCC</td>
    		</tr>
    		<tr>
    					<td >A</td>
    					<td >B</td>
    					<td nowrap="nowrap" >CCC</td>
    					<td nowrap="nowrap" >CCC</td>
    		</tr>
    		<tr>
    				<td >A</td>
    				<td >B</td>
    				<td nowrap="nowrap" >CCC</td>
    				<td nowrap="nowrap" >CCC</td>
    		</tr>
    		<tr>
    					<td >A</td>
    					<td >B</td>
    					<td nowrap="nowrap" >CCC</td>
    					<td nowrap="nowrap" >CCC</td>
    		</tr>
    		<tr>
    				<td >A</td>
    				<td >B</td>
    				<td nowrap="nowrap" >CCC</td>
    				<td nowrap="nowrap" >CCC</td>
    		</tr>
    		</tbody>
    </table>
    </div>
    </div>
    

  • 相关阅读:
    每天一个linux命令(1):man命令
    安卓名词积累
    每天一个Linux命令:目录
    ubuntu下Python的安装和使用
    嵌入式基础知识(1):存储
    2月份学习笔记
    AndroidStudio 中的坑Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRID
    AndroidStudio开发出现Warning:Gradle version 2.10 is required. Current version is 2.8. If u
    Git 问题
    判断年 月的值
  • 原文地址:https://www.cnblogs.com/wblade/p/1669976.html
Copyright © 2020-2023  润新知