JS dynamic Add Delete upload attachment code

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax button class code delete document file function

<!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>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<title> webpage Special effects dynamic Increase Delete upload attachment code </title>
</head>

<body>

JS implements the file field code for multiple upload attachments
<style type= "Text/css Tutorial" >. file {font:10pt; color:black;} </style>
< Script language= "Web effects"
      function AddFile () {
            var filediv = document.all[' Filediv '];
           var strhtml = ' <span><input type= ' file ' >&nbsp;&nbsp;<button onclick= "RemoveFile (parentnode);" > Delete </button><br></span> ';
           filediv.innerhtml + = strhtml;
     }
     
      function removefile (obj) {
            Obj.removenode (TRUE);
     }
</script>
<form enctype= "Multipart/form-data"
      <div ID= "Filediv" ></div>
      <a href= javascript:void (AddFile ()); "Class=" File "> Add attachment </a>
</form>//method Two like Hotmail mailbox add attachment mode dynamic increase upload attachment code

<div id= "Files" >
<div>
<input Type=button onclick= "Add ();" Value=attacthment>


<script>
var html= "<input name=title type=file> <input type=button value=delete onclick=" Remove (This) ">";
function Add ()
{
var o=document.all["files"];
var div=document.createelement ("div");
div.innerhtml=html;
O.appendchild (DIV);
Div.childnodes[0].click ();
}
function Remove (obj)
{
Obj.parentelement.parentelement.removechild (obj.parentelement);
}
</script>
Method Three js dynamic increase delete upload attachment code

<style type= "Text/css" > file {font:10pt; color:black;} </style>
<script language= "JavaScript" >
var i=0;
function AddFile () {
i++;

Currrow=conditiontable.insertrow ();
Cellc=currrow.insertcell ();
cellccontext= ' <input type= "file" Name= "file+" +i>&nbsp;&nbsp;<button onclick= "RemoveFile ();" > Removal </button><br> ';
Cellc.innerhtml=cellccontext;

}
function Findtd (o) {
if (o.nodename== "TR" | | o.nodename== "table") return;
if (o.nodename== "TD")
Return (o);
Else
return (o.parentelement);
}
function RemoveFile () {
o = Findtd (event.srcelement);
alert (o.parentelement.rowindex*1);
Conditiontable.deleterow (o.parentelement.rowindex*1);

}
function UploadFile () {

}


</script>
<form enctype= "Multipart/form-data" >
<a href= "Javascript:void (AddFile ());" class= "file" > Add attachment </a> <a href= "Javascript:void (UploadFile ());" class= "file" > Upload attachment </a>
<div id= "Filediv" style= ' Height:150px;top:150px;left:0px;overflow-x:auto;overflow-y:auto; Border-width:1pt;border-color:black; ' >
<table id=conditiontable border=1 >
</table>
</div>

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