網頁製作奇思妙想 表格也加捲軸

來源:互聯網
上載者:User
網頁

其實這個東西沒什麼技術含量,就是給大家提供一個給表格加捲軸的思路。

下面是原始碼:

<html><head><title>My table</title><style>.table0 { height:90%;}.table0 caption{ width:100%; height:26px; line-height:26px; font-size:20px; font-color:black; font-weight:900; letter-spacing:5px;}.table0 thead td { text-align:center; vertical-align:middle; height:20px; line-height:18px; font-size:14px; font-color:black; font-weight:bold; padding-top:2px; padding-bottom:2px; border:#555 1px solid; margin:0px;}.table0 tfoot td{ text-align:left; vertical-align:middle; height:20px; line-height:18px; font-size:12px; font-color:black; font-weight:bold; padding-top:2px; padding-bottom:2px; padding-left:12px; padding-right:12px; border:#555 1px solid;}.table0 tbody td { width:100%; height:auto; border:#555 1px solid; padding:0px; margin:0px;}.table1 tbody td { text-align:left; vertical-align:middle; height:20px; line-height:18px; font-size:14px; font-color:#444; font-weight:normal; padding-top:2px; padding-bottom:2px; padding-left:12px; padding-right:12px; border-right:#555 1px solid; border-bottom:#555 1px solid; overflow:hidden; text-overflow:ellipsis; word-break:keep-all; word-wrap:normal;}</style><script>function init(){ theT=createTable("我的收藏夾",["Group:150","Name:300","URL:200","Visited:100","Modify:100","Delete:100"]); //參數說明:createTable(strCaption,colHeads) //strCaption 標題 //colHeads 是一個array,每個item的格式是 名稱:寬度 的字串 for(var i=0;i<40;i++){ theR=theT.insertRow(); for(var j=0;j<7;j++){ theC=theR.insertCell(); theC.innerText=j; } }}function createTable(strCaption,colHeads){ //參數說明:colHeads 是一個array,每個item的格式是 名稱:寬度 的字串 //產生表格 oTable=document.createElement("table"); document.body.insertBefore(oTable); //設定class oTable.className="table0"; with(oTable.style){ tableLayout="fixed"; borderCollapse="collapse" borderSpacing="0px"; } //設定變數 oTCaption=oTable.createCaption(); oTHead=oTable.createTHead(); oTFoot=oTable.createTFoot(); //產生標題 oTCaption.innerText=strCaption; //設定列寬 oTHead.insertRow(); for(var i=0;i<colHeads.length;i++){ tHeadName=colHeads[i].split(":")[0]; tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]); theCell=oTHead.rows[0].insertCell(); theCell.style.width=tHeadWidth; } theCell=oTHead.rows[0].insertCell(); theCell.width=20; oTHead.rows[0].style.display="none"; //產生表頭 oTHead.insertRow(); for(var i=0;i<colHeads.length;i++){ tHeadName=colHeads[i].split(":")[0]; tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]); theCell=oTHead.rows[1].insertCell(); theCell.innerText=tHeadName; theCell.style.width=tHeadWidth; } theCell=oTHead.rows[1].insertCell(); theCell.width=24; //產生表腳 oTFoot.insertRow(); theCell=oTFoot.rows[0].insertCell(); theCell.innerHTML="<marquee scrollDelay=50 scrollAmount=2>Copy rights 2005. Hutia presents.</marquee>"; theCell=oTFoot.rows[0].insertCell(); theCell.colSpan=colHeads.length-1; theCell=oTFoot.rows[0].insertCell(); theCell.width=20; //產生主體 oTable.all.tags("Tbody")[0].insertRow(); theCell=oTable.all.tags("Tbody")[0].rows[0].insertCell(); theCell.colSpan=colHeads.length+1; oMain=document.createElement("DIV"); theCell.insertBefore(oMain); with(oMain.style){ width="100%"; height="100%"; overflowY="auto"; overflowX="hidden"; margin="0px"; marginLeft="-1px"; } oTBody=document.createElement("table"); oMain.insertBefore(oTBody); oTable.oTBody=oTBody; //禁止選擇 oTCaption.onselectstart=oTHead.onselectstart=oTFoot.onselectstart=function(){return(false);} //設定class oTBody.className="table1"; with(oTBody.style){ width=oTable.offsetWidth-15; tableLayout="fixed"; borderCollapse="collapse" borderSpacing="0px"; padding="0px"; margin="0px"; } //初始化列寬 oTBody.insertRow(); for(var i=0;i<colHeads.length;i++){ tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]); theCell=oTBody.rows[0].insertCell(); theCell.style.width=tHeadWidth; } oTBody.rows[0].style.display="none"; return(oTBody);}function insertRow(){ var intL=oTBody.rows.length; theRow=oTBody.insertRow(); theRow.index=intL; theRow.onmouseover=rowOnMouseOver; theRow.onmouseout=rowOnMouseOut; theRow.onclick=rowOnClick; for(var i=0;i<colHeads.length;i++){ theCell=theRow.insertCell(); theCell.tabIndex=0; theCell.hideFocus=true; theCell.colIndex=i; theCell.onmouseover=function(){this.focus();}; theCell.onmouseout=cellOnBlur; theCell.onfocus=cellOnFocus; theCell.onblur=cellOnBlur; } theRow.cells[0].innerText=strGroup?strGroup:"ROOT"; theRow.cells[1].innerText=strName?strName:"Untitled Document."; theRow.cells[2].innerText=strURL?strURL:"Unspecified URL"; theRow.cells[3].innerHTML=strVisited?"Yes".fontcolor("red"):"Unknow"; theRow.cells[4].innerHTML=strModify?"Yes".fontcolor("red"):"No".fontcolor("Green"); theRow.cells[5].innerHTML="Delete".fontcolor("red");}</script></head><body ></body></html>

    [Ctrl+A 全部選擇 提示:你可先修改部分代碼,再按運行]



相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。