Twitter bootstrap input tags not working with Jquery before()

后端 未结 1 696
无人共我
无人共我 2021-01-26 20:26

I am using Jquery to clone() a div and change its children\'s id, one of the children is a Bootstrap-tagsinput.

You can find a Demo here.

After clicking

1条回答
  •  梦毁少年i
    2021-01-26 20:49

    Try calling .tagsinput() on #tag2 after adding it to the page.

    $('#addrun').before(s.parent().html());
    $('#tag2').tagsinput();
    

    Edit:

    This is probably due to how the TagsInput plugin initializes itself. What I would do is create a template of your empty run container and hide it on the page or load it via JavaScript.


    Then you clone the ControlGroupTemplate and apply the TagsInput method to it.

    var s = $('#ControlGroupTemplate')
      .clone()
      .attr('id', '#run' + (++runNum))
      .wrap('
    '); s.find('#tag1').attr('id', 'tag2'); $('#addrun').before(s.parent().html()); $('#tag2').tagsinput();

    I would even use this method to add your initial run to the page in your document.ready() handler.

    0 讨论(0)
提交回复
热议问题