This example shares the specific code for jQuery to dynamically add and delete input boxes for your reference. The specific content is as follows
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Options</title> <script type="text/javascript" src="js/jquery-1.8."></script> <script> $(function(){ // Add options $("#opbtn").click(function(){ if($("#opts>li").size() < 6){// Add up to 6 options $("#opts").append("<li><input /></li>"); }else{// The number of prompt options has reached the maximum $("#optips").html("The number of options has reached the maximum and cannot be added!"); $("#optips").css({"color":"red"}); } }); // Delete option $("#delbtn").click(function(){ if($("#opts>li").size() <= 0){ $("#optips").html("No option can be deleted!"); $("#optips").css({"color":"red"}); } else{ // Delete option, delete the last one each time $("#opts>li").last().remove(); } }); }); </script> <style> *{ margin: 0px; padding: 0px; } #dv{ width: 100px; height: 100px; background-color: yellow; margin: 0px auto 0px; } </style> </head> <body> <div style="margin: 50px;"> <input type="button" value="Add Options"/> <input type="button" value="Delete Options"/> <input type="button" value="Encircling DIV"/> <ol type="A"></ol> <!-- Prompt --> <span ></span> </div> </body> </html>
The above is the jQuery implementation dynamically add and delete input boxes introduced by the editor. It is explained and integrated in detail. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!