[JavaScript] table template operations

Source: Internet
Author: User
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en" >

< Html >

< Head >

< Title > </ Title >

< Meta Name = "Generator" Content = "Microsoft Visual Studio. net7.1" >

< Meta Name = "Vs_targetschema" Content = "Http://schemas.microsoft.com/intellisense/ie5" >

< Script Language = "JavaScript" >

VaR Objtable;



Function Pageload ()

{

Objtable = Document. getelementbyid ( " Tbnew " ); // Find the operation table

}



Function Tdvalue ()

{

VaR Objtemprow = Objtable. Rows [ 0 ]; // Find the table template row

VaR Objnewrow = Objtable. insertrow (objtable. Rows. Length ); // Add a row at the end of the table

Objnewrow. ID = Objtable. Rows. Length -   1 ;

// Create new line content with template line

For ( VaR I = 0 ; I < Objtemprow. cells. length; I ++ )

{

VaR Objnewcell = Objnewrow. insertcell (I );



Objnewcell. innerhtml = Objtemprow. cells [I]. innerhtml;

}

}



Function Deletetablerow ()

{

If (Objtable. Rows. Length - 1   >   0 )

{

Objtable. deleterow (objtable. Rows. Length-1);

}

Else

{

//

}

}



Window. onload = Pageload;

</ Script >

</ Head >

< Body >

< Form ID = "Form1" Name = "Form1" >

< Input ID = "Btninsert" Name = "Btninsert" Type = "Button" Onclick = "Tdvalue ()" Value = "Add a new line"   />

< Input ID = "Btndelete" Name = "Btndelete" Type = "Button" Onclick = "Deletetablerow ()" Value = "Delete last line"   />

</ Form >

< Table ID = "Tbnew" Cellspacing = "1" Cellpadding = "1" Width = "100%" Border = "1" >



<! -- Here is the template line. -->

< Tr >

< TD > < Input ID = "Txtdata_1" Name = "Txtdata_1" Type = "Text" Value = "" /> </ TD >

< TD > < Input ID = "Txtdata_2" Name = "Txtdata_2" Type = "Text" Value = "" /> </ TD >

< TD > < Input ID = "Txtdata_3" Name = "Txtdata_3" Type = "Text" Value = "" /> </ TD >

</ Tr >

<! -- ------------ -->



</ Table >

</ 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.