Copy Code code as follows:
<script type= "Text/javascript" src= "Jquery.js" ></script>
<body>
<form action= "" method= "Post" enctype= "Multipart/form-data" >
<label> Please select the uploaded picture </label>
<a href= "javascript:addimg ()" > Add picture </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 picture"/>
</form>
<script type= "Text/javascript" >
$ (document). Ready (function () {
Bindlistener ();
});
Used to bind events (use Unbind to avoid duplicate 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> ');
To add an event listener for a new element node
Bindlistener ();
}
</script>