JS dynamic Add Delete upload attachment code

Source: Internet
Author: User

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Code </title>

<body>

JS implementation of multiple upload attachment file field code
<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 attachments </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

<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>

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.