This article introduces the use of JS and jquery to implement dynamic file upload Operation button to add and delete, specifically for example, hope to help you all
The JavaScript implementation code is as follows: <! 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>jquery file upload </title> <script type=" Text/javascript "src=" Jquery-1.7.2.js "></script> <script type=" Text/javascript "> var addmore = function () { var div = document.getElementById ("Div2"); var br = document.createelement ("br"); var input = document. createelement ("input"); var button = document.createelement ("input"); Input.setattribute ("type", " File "); Button.setattribute (" type "," button "); Button.setattribute (" value "," Remove "); Button.onclick = function () { div.removechild (BR); div.removechild (input); div.removechild (Button) ; } Div.appendchild (BR); div.appendchild (input); div.appendchild (button); } //Node mobile //$ ( function () { //}); </script> </head> <body> <div id= " Div1 "> <input type=" file "id=" Upload "/> " <input "button" type= "id=" btn "more" value= " Addmore (); " /> </div> <div id= "Div2" ></div> </body> </html> jquery Implementation code is as follows: <! 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>jquery file upload </title> <title>jquery1</title> <script type= "Text/javascript" src= "jquery-1.7.2.js" ></script> <script type= "Text/javascrip"T "> /** var addmore = function () { var div = document.getElementById (" Div2 "); var br = Document.creat Eelement ("BR"); var input = document.createelement ("input"); var button = document.createelement ("input"); Input.setattribute ("type", "file"); Button.setattribute ("type", "button"); Button.setattribute ("Value", "Remove"); Button.onclick = function () { div.removechild (BR); Div.removechild (Input); div.removechild (button); } Div.appendchild (BR); Div.appendchild (Input); div.appendchild (button); }**/ //jquery Implement File Upload button Add and remove $ (function () { $ ("Input[type=button]"). Click (function () { var br = $ ("<br>"); var input = $ ("<input type=" File '/> '); var button = $ ("<input type= ' button ' value= ' Remove '/>"); $ ("#div1"). Append (BR). Append (input). Append (Button); Button.Click (function () { br.remove (); Ut.remove (); button.remove (); }); }); }); </script> </head> <body> <div id= "Div1" > <input type= "file" id= "upload"/> <input "type=" Button "id=" BTN "value=" more "onclick=" Addmore (); /> </div> <div id= "Div2" ></div> </body> </html>