Dynamically Add/delete HTML elements

Source: Internet
Author: User

This article uses dynamic deletion of HTML elements (consult experts)

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en" >
< Html >
< Head >
< Title > Webform2 </ Title >
< Meta Name = "Generator" Content = "Microsoft Visual Studio. net7.1" >
< Meta Name = "Code_language" Content = "C #" >
< Meta Name = "Vs_defaultclientscript" Content = "JavaScript" >
< Meta Name = "Vs_targetschema" Content = "Http://schemas.microsoft.com/intellisense/ie5" >
< Script Language = "JavaScript" >
VaR Count =   0 ;
VaR Maxfile =   5 ; // Maximum allowed quantity

// Add Element
Function Addupload () {
If (Count > = Maxfile) Return ; // Restrict up to maxfile file boxes
Count ++ ;

// Each time the HTML object with different auto-increment IDS is appended to the end of the container
VaR Newdiv = " <Div id = divupload "   + Count + " > "
+   " <Input id = File "   + Count +   " Type = file size = 50 name = upload> "
+   " <A href = javascript: delupload ('divupload "   + Count +   " ');> Delete </a> "
+   " </Div> " ;
Document. getelementbyid ( " Uploadcontent " ). Insertadjacenthtml ( " Beforeend " , Newdiv );
}

// Deletes a specified element.
Function Delupload (DIVA) {
Count--;
Document. getelementbyid (DIVA). parentnode. removechild (document. getelementbyid (DIVA ));
}

</ Script >
</ Head >
< Body Ms_positioning = "Gridlayout" >
< Form ID = "Form1" Method = "Post" Runat = "Server" Enctype = "Multipart/form-Data" >
< Div >
< Table >
< Tr >
< TD ID = "Tdrrmove" Width = "2000" >

<! -- Undertake the HTML container of the entire file box -->
< Div ID = "Uploadcontent" >
<! -- Default file box
<Div id = div1> <input id = file1 type = file size = 50 name = upload> </div> -->
</ Div >

</ TD >
</ Tr >
</ Table >
</ Div >
< A Href = "Javascript: addupload ()" > Add attachment </ A >
< BR />
< BR />
</ 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.