Jquery automatically adds a column to the table

Source: Internet
Author: User

 

<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Test. aspx. CS " Inherits = " Test " %>

<! Doctype HTML public"-// W3C // dtd xhtml 1.0 transitional // en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = " Http://www.w3.org/1999/xhtml " >
<Head>
<Title> </title>
<SCRIPT src = " JS/jquery-1.4.1.min.js " Mce_src = " JS/jquery-1.4.1.min.js " Type = " Text/JavaScript " > </SCRIPT>
<SCRIPT type = " Text/JavaScript " >
Function addcol (){
$ Col = $ (" <TD> added columns </TD> " );
$ ( " # Tab1> tbody> tr " ). Append ($ col );
}
Function delcol (){
// Remove the last column
$ ( " # Tab1 TR: Last-child " ). Remove ();
// Remove the first column
// $ ("# Tab1 TR: First-Child"). Remove ();
// Remove the specified column. Note: This index starts from 1.
// $ ("# Tab1 TR: Nth-child (2)"). Remove ();
// Remove a column other than the first column
// $ ("# Tab1 TR: Not (: Nth-Child (1)"). Remove ();
}
</SCRIPT>

</Head>
<Body>
<Input id = " Button1 " Type = " Button " Onclick = " Addcol () " Value = " Add Column " />
<Input id = " Button2 " Type = " Button " Onclick = " Delcol () " Value = " Reduce Column " />
<Table id = " Tab1 " Border = " 1 " Style = " Width: 200px; " >

<Tbody>
<Tr>
<TD> 1 </TD>
<TD> Hello </TD>
</Tr>
<Tr>
<TD> 2 </TD>
<TD> world </TD>
</Tr>
<Tr>
<TD> 3 </TD>
<TD> Prince pie </TD>
</Tr>
</Tbody>
</Table>
</Body>
</Html>

 

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.