JAVASCRIPT Talbe Operations

Source: Internet
Author: User


<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script language= "javascript" type= "Text/javascript" >
function AddRow () {
var newtr = document.getElementById ("TestTable"). InsertRow (document.getElementById ("TestTable"). Rows.length);
var newnametd = Newtr.insertcell (0);
newnametd.innerhtml = "AA";
var newnametd = Newtr.insertcell (1);
newnametd.innerhtml = "<input name= ' LastName ' id= ' LastName ' type= ' text '/> ';
var newnametd = Newtr.insertcell (2);
newnametd.innerhtml = "<input name= ' BirthDay ' id= ' BirthDay ' type= ' text '/> ';
var newnametd = Newtr.insertcell (3);
newnametd.innerhtml = "<input name= ' age ' id= ' age ' type= ' text '/>";
}
function InsertRow () {
var otable = document.getElementById ("Table_info");
var oTr = Otable.insertrow ();
var oTd = Otr.insertcell ();
otd.innerhtml = "New Line added";
}
function InsertRow2 () {
Get Table Object
var table = document.getElementById ("Table_info2");
Find the TD to which you want to add a button, with the first column in the first row of the table example
var oTd = table.rows[0].cells[0];
Add a button to TD, add the code before the TD content is emptied and given the button
otd.innerhtml = "<button onclick= ' insertRow22 () ' > Add charge </button>";
}
function InsertRow22 () {
var otable = document.getElementById ("Table_info2");
var oTr = Otable.insertrow ();
var oTd = Otr.insertcell ();
otd.innerhtml = "New Line added";
}
function InsertRow3 () {
Get Table Object
var table = document.getElementById ("Table_info3");
Find the TD to which you want to add a button, with the first column in the first row of the table example
var oTd2 = Table.rows[0].insertcell ();
otd2.innerhtml = "&nbps;";
}
function Tablediv () {
var maxrow = 4;
var maxcol = 8;
var strtbody = ["<table border= ' 1 ' ><tbody>"];
for (var i = 0; i < MaxRow; i++) {
Strtbody.push ("<tr>");
for (var j = 0; J < Maxcol; J + +) {
Strtbody.push ("<td>test</td>");
}
Strtbody.push ("</tr>");
}
Strtbody.push ("</tbody></table>");
var obj = document.getElementById ("Tablediv");
obj.innerhtml = Strtbody.join ("");
}
function init () {
var _table, _tbody, TR, TD, Text, MaxRow, Maxcol;
var docbody = document.body;
var _doc = document;
MaxRow = 5;
Maxcol = 8;
_table = _doc.createelement ("table");
_table.border = "1";
_table.style.tablelayout = "fixed";
_tbody = _doc.createelement ("tbody");
_table.insertbefore (_tbody, NULL);
Docbody.insertbefore (_table, NULL);
for (var i = 0; i < MaxRow; i++) {
TR = _doc.createelement ("tr");
_tbody.insertbefore (tr, NULL);
for (var j = 0; J < Maxcol; J + +) {
TD = _doc.createelement ("TD");
Text = _doc.createtextnode ("text");
Td.insertbefore (text, NULL);
Tr.insertbefore (TD, NULL);
}
}
}
</script>
<body>
<div>
<table id= "TestTable" border= ' 1 ' cellspacing= "1" >
<tr>
<th>
FirstName
</th>
<th>
LastName
</th>
<th>
BirthDay
</th>
<th>
Age
</th>
</tr>
<tr>
<td>
Jim
</td>
<td>
Green
</td>
<td>
L.a
</td>
<td>
23
</td>
</tr>
<tr>
<td>
Andrew
</td>
<td>
Hou
</td>
<td>
Xi ' an
</td>
<td>
25
</td>
</tr>
</table>
<input type= "button" id= "AAA" value= "+add new Row" onclick= "AddRow ();"/>
</div>
<br/>
<br/>
<div>
<input type= "button" value= "buttons Add line" onclick= "InsertRow ();"/>
<table id= "Table_info" border= "1" >
<tr>
<th>
Name
</th>
<th>
Age
</th>
</tr>
</table>
</div>
<br/>
<br/>
<div>
Add line "onclick=" InsertRow2 () <input type= "button" value= "/>
<table id= "Table_info2" border= "1" >
<tr>
<th>
Name
</th>
<th>
Age
</th>
</tr>
</table>
</div>
<br/>
<br/>
<div>
<input type= "button" value= "Continuous Add Column" onclick= "INSERTROW3 ();"/>
<table id= "Table_info3" border= "1" >
<tr>
<th>
Name
</th>
<th>
Age
</th>
</tr>
</table>
</div>
<br/>
<br/>
<div>
<input type= "button" value= "Add a Table" onclick= "Tablediv ();"/>
<div id= "Tablediv"/>
</div>
<br/>
<br/>
<div>
<input type= "button" value= "continuous Add Table" onclick= "init ();"/>
</div>
</body>

JAVASCRIPT Talbe Operations

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.