<! 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 = "text/html; charset = UTF-8"/>
<Title> use the DOM method to upload multiple attachments to the client </title>
<Script language = "javascript" type = "text/javascript">
Function addFile (){
// Create a tr tag
Var tr1 = document. createElement ("tr ");
// Create a td tag
Var td1 = document. createElement ("td ");
// Create an input tag
Var input1 = document. createElement ("input ");
// Add the type = file attribute to input
Input1.setAttribute ("type", "file ");
// Append the first created td to tr1
Td1.appendChild (input1 );
Tr1.appendChild (td1 );
// Create a new td
Var td1 = document. createElement ("td ");
// Create an input tag
Var input2 = document. createElement ("input ");
// Add the type = "button" and value = "delete" attribute to the input.
Input2.setAttribute ("type", "button ");
Input2.setAttribute ("value", "delete ");
// Add the nclick event to the input file and pass this to the tag object input. Then, execute the input file to pass the input object.
Input2.setAttribute ("onclick", "delFile (this )");
// Append input to td
Td1.appendChild (input2 );
// Add td to tr1
Tr1.appendChild (td1 );
// Append tr1 to table
Document. getElementById ("id2"). appendChild (tr1 );
}
Function delFile (this1 ){
Var p = this1.parentNode;
Var p2 = p. parentNode;
Var p3 = p2.parentNode;
// Delete the tr tag to which the tag belongs. Save the result of deleting the tag.
Var element = p3.removeChild (p2 );
}
</Script>
</Head>
<Body>
<Div id = "id1">
<Table id = "id2">
<Tr>
<Td> <input type = "file" value = ""> </td>
<Td> <input type = "button" value = "add" onclick = "addFile ()"> </td>
</Tr>
</Table>
</Div>
</Body>
</Html>
From the column of youngerhao