Table
Table Properties:
Border: Defines the border width of the table, which defaults to 0, which is no border. <table border= "1" >
Title: The information that is prompted when the mouse moves over the table.
CellPadding: Specifies the gap between the edge of the unit and its contents.
CellSpacing: Specifies the white space between cells.
Th, TD Properties:
Colspan: Represents a horizontal merge cell ()
RowSpan: Represents a vertically merged cell ()
Connotation label
<caption></caption>: Table header information.
<tr></tr>: Define a table row;
<th></th>: Defines a table header, or, in the case of plain text, it is shown in bold style by default.
<tbody></tbody>: It can be understood as the content area of a table, which is used when Chrome and FF browsers dynamically insert rows through the DOM. If you do not do DOM operations, you do not have to add.
<td></td>: Define a cell;
Table forms are written in two ways:
<body>
<table border= "1" >
<tr>
<th> name </th>
<th> Telephone </th>
<th> Telephone </th>
</tr>
<tr>
<td>bill gates</td>
<td>555 854</td>
<td>555 855</td>
</tr>
</table>
<table border= "1" >
<tr>
<th> name </th>
<td>bill gates</td>
</tr>
<tr>
<th> Telephone </th>
<td>555 854</td>
</tr>
<tr>
<th> Telephone </th>
<td>555 855</td>
</tr>
</table>
</body>
Table header:
name |
Telephone |
Telephone |
Bill Gates |
555 77 854 |
555 77 855 |
Vertical table Header:
Name |
Bill Gates |
Phone |
555 77 854 |
Phone |
555 77 855 |
More uncommon attributes and sub-tags in the <table> tab:
Summary attribute: used to summarize the contents of the entire table. It is important for the search engine to record information about the robot.
bordercolor Property: used to set the color of the table border. However, it does not show the same effect in different browsers.
(using the BorderColor property is not recommended, but it is recommended to use the border property of the CSS style sheet to set it)
cellspacing Property: used to set the spacing between cells in a table.
(It is recommended to use the Border-collapse property of the CSS style sheet to set it)
<caption> Tags: represents a large header for a table that can appear anywhere between <table>.
It is important for the search engine to record information about the robot.
<th> Tag: The name of the row or column used to represent the table.
the scope property of the <th> tag : specifically used for the Zone branch name and column name. such as: <th scope= ' Row ' > or <th scope= ' col ' >
<table> also contains:<thead>, <tbody>, <tfoot> tags. they represent the table header, table body, and table feet, respectively.
When printing Web page content, if the table is large,,<thead> and <tfoot> will appear on each page.
(Note: Not valid in IE, but valid in Firefox)
The classic table code is as follows:
|
|
<title> Financial Statements </title> |
<style type= "Text/css" > |
<!-- |
. datalist{ |
border:1px solid #429fff; /* Table Border */ |
font-family:arial; |
Border-collapse:collapse; /* Border overlap */ |
} |
. DataList tr:hover{ |
Background-color: #c4e4ff; /* Dynamic discoloration, IE6 invalid! */ |
} |
. DataList caption{ |
padding-top:3px; |
padding-bottom:2px; |
Font:bold 1.1em; |
Background-color: #f0f7ff; |
border:1px solid #429fff; /* Table Header Border */ |
} |
. DataList th{ |
border:1px solid #429fff; /* row, Column name border */ |
Background-color: #d2e8ff; |
Font-weight:bold; |
padding-top:4px; padding-bottom:4px; |
padding-left:10px; padding-right:10px; |
Text-align:center; |
} |
. DataList td{ |
border:1px solid #429fff; /* Cell Border */ |
Text-align:right; |
padding:4px; |
} |
- |
</style> |
|
<body> |
<table class= "DataList" summary= "financial statement" > |
<caption> Financial Statements 2005-2008</caption> |
<thead> |
<tr> |
<th> </th> |
<th scope= "Col" >2005</th> |
<th scope= "Col" >2006</th> |
<th scope= "Col" >2007</th> |
<th scope= "Col" >2008</th> |
</tr> |
</thead> |
<tbody> |
<tr> |
<th scope= "Row" > Grants </th> |
<td>11,980</td> |
<td>12,650</td> |
<td>9,700</td> |
<td>10,600</td> |
</tr> |
<tr> |
<th scope= "Row" > Donations </th> |
<td>4,780</td> |
<td>4,989</td> |
<td>6,700</td> |
<td>6,590</td> |
</tr> |
<tr> |
<th scope= "Row" > Investment </th> |
<td>8,000</td> |
<td>8,100</td> |
<td>8,760</td> |
<td>8,490</td> |
</tr> |
<tr> |
<th scope= "Row" > Fundraising </th> |
<td>3,200</td> |
<td>3,120</td> |
<td>3,700</td> |
<td>4,210</td> |
</tr> |
</tbody> |
<tfoot> |
<tr> |
<TD colspan= "5" >2008 annual statistics </td> |
</tr> |
</tfoot> |
</table> |
</body> |
|
The display results are as follows:
Financial Statements 2005-2008
|
2005 |
2006 |
|
|
Funding |
11,980 |
12,650 |
9,700 |
10,600 |
Donations |
4,780 |
4,989 |
6,700 |
6,590 |
Investment |
8,000 |
8,100 |
8,760 |
8,490 |
Fundraising |
3,200 |
3,120 |
3,700 |
4,210 |
Sales |
28,400 |
27,100 |
27,950 |
29,050 |
Miscellaneous |
2,100 |
1,900 |
1,300 |
1,760 |
Total |
58,460 |
57,859 |
58,110 |
60,700 |
2008 Statistics |
Attention:
IE6 only <a> tag support: Hover pseudo class, the remaining tags are not supported!
and the pseudo-class of the <a> tag is in order: a:active A:link, a:visited, a:hover
Using Dom's methods and properties to implement dynamic operation of tables
A dynamic addition of A row using the DOM
<script language= "JavaScript" > |
window.onload=function() { |
Insert a row |
var oTr = document.getElementById ("MyTable"). InsertRow (2); |
var atext = new Array(); |
atext[0] = document.createTextNode ("contents of cell1"); |
atext[1] = document.createTextNode ("contents of cell2"); |
atext[2] = document.createTextNode ("contents of Cell3"); |
atext[3] = document.createTextNode ("contents of Cell4"); |
atext[4] = document.createTextNode ("contents of cell5"); |
for (var i=0; i<atext.length;i++) { |
var oTd = Otr.insertcell (i); |
Otd.appendchild (Atext[i]); |
} |
} |
</script> |
B modifying cell contents with DOM
<script language= "JavaScript" > |
window.onload=function() { |
var otable = document.getElementById ("MyTable"); |
Modify cell contents |
otable.rows[3].cells[4].innerhtml = "content changed"; |
} |
</script> |
C Delete a cell or row using the DOM
<script language= "JavaScript" > |
window.onload=function() { |
var otable = document.getElementById ("MyTable"); |
Delete a row, followed by the line number is automatically padded |
Otable.deleterow (2); |
Delete a cell, and the back is automatically padded |
otable.rows[2].deletecell (1); |
} |
</script> |
D dynamically add a column using the DOM and dynamically delete a row
<script language= "JavaScript" > |
function Mydelete () { |
var otable = document.getElementById ("MyTable"); |
Delete the row |
this. ParentNode.parentNode.parentNode.removeChild (this. parentnode.parentnode); |
} |
|
window.onload=function() { |
var otable = document.getElementById ("MyTable"); |
var oTd; |
Add a Delete link dynamically |
for (var i=1; i<otable.rows.length;i++) { |
OTd = Otable.rows[i].insertcell (5); |
otd.innerhtml = "<a href= ' # ' >delete</a>"; |
OTd.firstChild.onclick = Mydelete; Add Delete Event |
} |
} |
</script> |
E dynamically delete a column using the DOM
<script language= "JavaScript"; |
function deletecolumn (otable,inum) { |
//Custom Delete Column function, That is, each row deletes the corresponding cell |
for ( var i= 0 ; i<otable.rows.length;i++) |
otable . Rows[i].deletecell (iNum); |
} |
|
window.onload= function () { |
var oTable = document.getElementById ("MyTable"); |
deletecolumn (otable, 2 ), //parameter 2: Indicates the column number to delete |
} |
</script> |
Complete.
HTML BODY Tag