Dynamically Add a table row (JavaScript)

Source: Internet
Author: User

<% & #64; Page Language = "Java" Import = "Java. util. *, Com. Page. Wash. giveclothing. *" pageencoding = "GBK" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> Add Table Information </title>
<Meta http-equiv = "Pragma" content = "no-Cache"/>
<Meta http-equiv = "cache-control" content = "no-Cache"/>
<Meta http-equiv = "expires" content = "0"/>
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3"/>
<Meta http-equiv = "Description" content = "this is my page"/>
<SCRIPT type = "text/JavaScript">

Function addrow ()
{
// Add a row
VaR I = tab1.rows. length;
VaR Nam = "'div1 '";
VaR cod = "Fuj" + I;
VaR newtr = tab1.insertrow ();
// Add a column
VaR newtd0 = newtr. insertcell ();
VaR newtd1 = newtr. insertcell ();
VaR newtd2 = newtr. insertcell ();
VaR newtd3 = newtr. insertcell ();
// Set the column content and attributes
Newtd0.innerhtml = '<input type = "checkbox" id = "box1" onclick = "getrow () "//> <input type =" hidden "name =" Fuj "id = '+ cod +'/> ';
Newtd1.innerhtml = "Clothes size ";
Newtd2.innerhtml = "Clothes ";
Newtd3.innerhtml = "processing type ";
}
Function delrow ()
{
// Delete a row
VaR Shu = 0;
VaR checou = Document. All ("box1 ");
For (VAR I = 0; I <checou. length; I ++)
{
If (checou [I]. Checked = true)
{
Shu ++;
}
}
If (Shu = checou. length)
{
Alert ('add at least one body ');
Return;
}
Else if (Shu = 0)
{
Alert ('select the information you want to delete ');
Return;
}
Else if (Shu = 1)
{
For (VAR I = 0; I <checou. length; I ++)
{
If (checou [I]. Checked = true)
{
Tab1.deleterow (I + 1 );
}
}
}
Else if (Shu> 1)
{
For (VAR a = 0; A <shu; A ++)
{
For (VAR I = 0; I <checou. length; I ++)
{
If (checou [I]. Checked = true)
{
Tab1.deleterow (I + 1 );
Break;
}
}
}
}
}
Function getrow ()
{
// Obtain the row Index
// The two parentelements are TD and TR respectively, and rowindex is the attribute of TR.
// This. parentelement. parentelement. rowindex
Cgetrow = Window. event. srcelement. parentelement. parentelement. rowindex;
}
</SCRIPT>
</Head>
<Body>
<Form name = "form1" Action = "$ {pagecontext. Request. contextpath}/giveclothing. do? Method = fujiafei "method =" Post ">
<Center>
<Fieldset>
<Legend> <strong> dynamically Add a table </strong> </legend>
<Input type = hidden id = "hid" name = "hid" //>
<Table id = "tab1" align = "center" border = "1" cellpadding = "4" cellspacing = "0" bordercolorlight = "#999999" bordercolordark = "# ffffff" Style = "width: 95%; Word-break: Break-all ">
<Thead>
<Tr>
<TH align = "center" width = "10%"> select </Th>
<TH align = "center" width = "15%"> Clothes size </Th>
<TH align = "center" width = "15%"> Clothes </Th>
<TH align = "center" width = "15%"> processing type </Th>
</Tr>
</Thead>
<Tr>
<TD> <input type = checkbox id = "box1" onclick = "getrow ()"/>
<Input type = "hidden" name = "Fuj" id = "fuji1"/>
</TD>
<TD> Clothes size </TD>
<TD> Clothes </TD>
<TD> processing type </TD>
</Tr>

</Table>
<Table align = "center" border = "1" cellpadding = "4" cellspacing = "0" bordercolorlight = "#999999" bordercolordark = "# ffffff" style = "width: 95%; Word-break: Break-all ">
<Tr>
<TD align = "right">
<Input type = "button" name = "Submit" value = "add a line" onclick = "javascript: addrow ();"/>
<Input type = "button" name = "Submit" value = "delete a row" onclick = "javascript: delrow ();"/>
</TD>
</Tr>
</Table>
</Form>
</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.