简体   繁体   中英

Can't use twitter-bootstrap popover in a <select> tag

I'm displaying a list in a <select> html tag and I want to display some details about each items with a popover. I loaded all the js files and I initialise for every <option> but it won't show any information.

 <select id="type_traitement" class="span10"> 
                <?php
                foreach ($type_traitement_simple as $tts) {
                    echo '<option value="' . $tts->id_type_traitement_simple . '">
                        <a href="#" 
                        rel="popover" data-content="' . $tts->description . '"
                        data-original-title="' . $tts->name . '"id="t_'.$tts->id_type_traitement_simple.'">                         
                        ' . $tts->name . '
                            </a>
                            </option>';

                    ?>
                    <script>  
                        $(function ()  
                        { $("#t_<?php echo $tts->id_type_traitement_simple ?>").popover();  
                        });  
                    </script>
                    <?php


                }
                ?>
            </select>

Update your foreach loop to look like the following.

<?php foreach($type_traitement_simple as $tts): ?>
<option value="<?php echo $tts->id_type_traitement_simple; ?>"
    data-content="<?php echo $tts->description; ?>"
    data-title="<?php echo $tts->name; ?>"><?php echo $tts->name; ?></option>
<?php endforeach; ?>

That should be the loop sorted. now put the below JavaScript after jQuery, Bootstrap Tooltip and Bootstrap Popover scripts.

<script type="text/javascript">
$(function() {
    $('#type_traitement option').popover({
        placement: 'right',
        trigger: 'manual'
    }).hover(function() {
        $(this).popover('toggle');
    });
});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM