Copy codeThe Code is as follows:
<Script type = "text/javascript" src = "jquery. js"> </script>
<Body>
<Form action = "" method = "post" enctype = "multipart/form-data">
<Label> select the uploaded image. </label>
<A href = "javascript: addimg ()"> Add an image </a>
<Div class = "mdiv" id = "mdiv">
<Div class = "iptdiv">
<Input type = "file" name = "img []" class = "ipt"/> <a href = "#" name = "rmlink"> X </a>
</Div>
</Div>
<Input type = "submit" name = "submit" value = "Upload image"/>
</Form>
<Script type = "text/javascript">
$ (Document). ready (function (){
BindListener ();
});
// Used to bind events (use unbind to avoid repeated binding)
Function bindListener (){
$ ("A [name = rmlink]"). unbind (). click (function (){
$ (This). parent (). remove ();
})
}
Function addimg (){
$ ("# Mdiv "). append ('<div class = "iptdiv"> <input type = "file" name = "img []" class = "ipt"/> <a href = "#" name = "rmlink"> X </a> </div> ');
// Add an event listener for the new element node
BindListener ();
}
</Script>