Add / remove input field dynamically with jQuery

前端 未结 12 1863
闹比i
闹比i 2020-12-02 06:14

I would like to use jquery to build a dynamic add/ remove form. IT should look like:

Name Type Required?

The example input :

  • Name Type Require
12条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 06:45

    You need to create the element.

    input = jQuery('');
    

    and then append it to the form.

    jQuery('#formID').append(input);
    

    to remove an input you use the remove functionality.

    jQuery('#inputid').remove();
    

    This is the basic idea, you may have feildsets that you append it too instead, or maybe append it after a specific element, but this is how to build anything dynamically really.

提交回复
热议问题