Make bootstrap popover work with custom html template

后端 未结 3 806
暖寄归人
暖寄归人 2021-02-05 04:38

I am using an input group textbox and I need the Bootstrap 3 popover to work and the popover template should be defined &n designed by me. So the html I have currently with

相关标签:
3条回答
  • 2021-02-05 04:50

    @code-jaff that is a great answer, but i noticed that the Working Demo's popover doesn't look like it's coming out of the button. If this is happening to anyone else, try adding container: 'body' to the popover options. Like this:

    $('body').popover({
        selector: '[rel=popover]',
        trigger: 'click',
        content: content,
        template: popoverTemplate,
        placement: "bottom",
        html: true,
        container: 'body'
    });
    
    0 讨论(0)
  • 2021-02-05 05:08

    I would prefer to have all the HTML in templates. It goes like this:

    Something in Javascript

    $(".btn").popover({
       template: $("#selector").html(),
       placement: "auto"
    });
    

    And in HTML

    <div id="selector">
        Anything you want in your popovers, either dynamic or static
    <div>
    
    0 讨论(0)
  • 2021-02-05 05:10

    you are missing the content of the popover, you'll need something like this

    $(document).ready(function () {
        var popoverTemplate = ['<div class="timePickerWrapper popover">',
            '<div class="arrow"></div>',
            '<div class="popover-content">',
            '</div>',
            '</div>'].join('');
    
        var content = ['<div class="timePickerCanvas">asfaf asfsadf</div>',
            '<div class="timePickerClock timePickerHours">asdf asdfasf</div>',
            '<div class="timePickerClock timePickerMinutes"> asfa </div>', ].join('');
    
    
        $('body').popover({
            selector: '[rel=popover]',
            trigger: 'click',
            content: content,
            template: popoverTemplate,
            placement: "bottom",
            html: true
        });
    });
    

    Working demo

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