JavaScript -- dynamically add and delete rows

Source: Internet
Author: User

<% @ page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%>
<%
string Path = request. getcontextpath ();
string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">

<Title> my JSP 'test. jsp 'starting page </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">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->

</Head>

<Body>
<Form action = "<% = PATH %>/news. do? Method = Add "method =" Post "enctype =" multipart/form-Data ">
<Input type = "hidden" name = "ID" value = "$ {NEWS. ID}">
<Table width = "90%" border = "0" align = "Left" cellpadding = "0" cellspacing = "1" class = "newtable">
<Tr>
<TD colspan = "2" id = "more">
Floor name <input type = "text" name = "name" size = "30" value = "111"> floor description <input type = "text" name = "info" Size = "30" value = "111"> <input type = "button" onclick = "AddFile (); "value =" add ">
</TD>
</Tr>
</Table>
</Form>
<SCRIPT type = "text/JavaScript">
VaR T = 1;
Function AddFile ()
{
VaR parent = Document. getelementbyid ("more ");
VaR BR = Document. createelement ("Br ");
VaR charname = Document. createtextnode ("floor name ")
VaR inputname = Document. createelement ("input ");
VaR charinfo = Document. createtextnode ("floor Introduction ")
VaR inputinfo = Document. createelement ("input ");
VaR button = Document. createelement ("input ");

Inputname. Values = "111 ";
Inputname. type = "text ";
Inputname. Name = "name [" + (T ++) + "]";
Inputname. size = "30 ";

Inputinfo. value = "111 ";
Inputinfo. type = "text ";
Inputinfo. Name = "info [" + (T ++) + "]";
Inputinfo. size = "30 ";

Button. type = "button ";
Button. value = "delete ";
Button. onclick = function ()
{
Parent. removechild (BR );
Parent. removechild (charname );
Parent. removechild (inputname );
Parent. removechild (charinfo );
Parent. removechild (inputinfo );
Parent. removechild (button );
};
Parent. appendchild (BR );
Parent. appendchild (charname );
Parent. appendchild (inputname );
Parent. appendchild (charinfo );
Parent. appendchild (inputinfo );
Parent. appendchild (button );
}
</SCRIPT>
</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.