Using jQuery to dynamically add form fields (or fieldsets) based on a dropdown box value

前端 未结 2 543
萌比男神i
萌比男神i 2020-12-17 03:34

As the title says, what I am trying to do is to have jQuery add a number of extra fieldsets based on the value selected in a drop-down box. For example, when the page loads,

2条回答
  •  不知归路
    2020-12-17 04:02

    Why are you cloning instead of just doing something like this (together with your current event listener)?

    $(".divWhereTheseGo").empty();
    var count = 0;
    while (count < maxItems) {
       $(".divWhereTheseGo").append("
    your form info
    "); count++; }

    The count in the fieldset is how you can handle the unique id issue.

提交回复
热议问题