Bootstrap toggle doesn't display well when added dynamically

后端 未结 3 1449

I\'m trying to add bootstrap toggle switch dynamically but it does not display well after adding it. Thanks for your help!



        
3条回答
  •  渐次进展
    2021-01-16 08:04

    You need to call the bootstrapSwitch() again after adding and with a new ID, class or else it will alter the states of existing toggle as well.

    $('.btn').on('click', function () {
        $('p').after(
            ''
        );
        $('.newBSswitch').bootstrapSwitch('state', true); // Add
    });
    

    JSfiddle

提交回复
热议问题