JS Add drop-down scroll bar to table

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax document drop function html javascript name set

<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 ("My Favorites", ["group:150", "name:300", "url:200", "visited:100", "modify:100", "delete:100"]);


//Parameter description: CreateTable (strcaption,colheads)


//strcaption title


//colheads is an array, and the format of each item is the name: width of the string


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) {


//Parameter description: Colheads is an array, the format of each item is the name: width of the string


//Generate table


otable=document.createelement ("table");


Document.body.insertBefore (otable);


//Set class


otable.classname= "Table0";


 


with (Otable.style) {


tablelayout= "fixed";


bordercollapse= "Collapse"


borderspacing= "0px";


 }


//Set Variable


otcaption=otable.createcaption ();


Othead=otable.createthead ();


Otfoot=otable.createtfoot ();


 


//Generate title


otcaption.innertext=strcaption;


 


//Set column width


Othead.insertrow ();


for (Var i=0;i<colheads.length;i++) {


theadname=colheads[i].split (":") [0];


Theadwidth=isnan (parseint colheads[i].split (":") [1])? Auto ":p Arseint (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";


 


//Generating header


Othead.insertrow ();


for (Var i=0;i<colheads.length;i++) {


theadname=colheads[i].split (":") [0];


Theadwidth=isnan (parseint colheads[i].split (":") [1])? Auto ":p Arseint (Colheads[i].split (": ") [1]);


Thecell=othead.rows[1].insertcell ();


Thecell.innertext=theadname;


Thecell.style.width=theadwidth;


 }


Thecell=othead.rows[1].insertcell ();


thecell.width=24;


 


//Build table foot


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;


 


//Generation principal


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;


//No choice


Otcaption.onselectstart=othead.onselectstart=otfoot.onselectstart=function () {return (false);}


 


//Set class


otbody.classname= "Table1";


with (Otbody.style) {


width=otable.offsetwidth-15;


tablelayout= "fixed";


bordercollapse= "Collapse"


borderspacing= "0px";


padding= "0px";


margin= "0px";


 }


 


//Initialize column width


Otbody.insertrow ();


for (Var i=0;i<colheads.length;i++) {


Theadwidth=isnan (parseint colheads[i].split (":") [1])? Auto ":p Arseint (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 onload= "init ();" >


</body>


</html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.