Bootstraps表行与弹出窗口一起使用时消失

时间:2019-06-04 22:51:58

标签: javascript jquery html twitter-bootstrap

当我单击表格行时尝试显示弹出框时,弹出框显示但从表格中删除了一行。

我尝试在行中添加div element并更改JQuery,但无济于事。

 
    <head>

   

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
        <link rel ="stylesheet" href = "test.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
    </head>

    <body>
            <div class="event-btn">
                    <div class = "btn-contents">
                    </div>
            </div>

            <div id = "s-cont">

              <table class = "table">
                    <thead>
                        <tr>
                            <th scope = "col"> Start </th>
                            <th scope = "col"> Session </th>
                            <th scope = "col"> Length </th>
                        </tr>
                    </thead>
                    <tr data-toggle ="popover" data-placement="top"  data-content = "HI" data-trigger = "click" >
                        <td> content 1 </td>
                        <td>content 2</td>
                        <td>content 3 </td>
                    </tr>
                    <tr data-toggle ="popover" data-placement="top"  data-content = "HI" data-trigger = "click" >
                        <td> content 1 </td>
                        <td>content 2</td>
                        <td>content 3 </td>
                    </tr>
                    <tr data-toggle ="popover" data-placement="top"  data-content = "HI" data-trigger = "click" >
                        <td>content 1 </td>
                        <td>content 2</td>
                        <td>content 3 </td>
                    </tr>
            </div>

            <script>
                $('[data-toggle="popover"]').popover({})
            </script>
    </body>
 

这在CodePen中有效,并且表中的行仍被删除。

1 个答案:

答案 0 :(得分:1)

当父元素上的某些样式会干扰弹出框时,您需要指定一个自定义容器,以使弹出框的HTML出现在该元素内,而不是link。使用data-container="body"来解决问题。

$('[data-toggle="popover"]').popover({})
<head>
 
        <meta name="viewport" content="width=device-width, initial-scale=1">
       
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
        <link rel ="stylesheet" href = "test.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
    </head>

    <body>
            <div class="event-btn">
                    <div class = "btn-contents"> </div>
            </div>

            <div id = "s-cont">

              <table class = "table">
                    <thead>
                        <tr>
                            <th scope = "col"> Start </th>
                            <th scope = "col"> Session </th>
                            <th scope = "col"> Length </th>
                        </tr>
                    </thead>
                    <tr data-toggle ="popover" data-placement="top"  data-container="body" data-content = "HI" data-trigger = "click" >
                        <td> content 1 </td>
                        <td>content 2</td>
                        <td>content 3 </td>
                    </tr>
                    <tr data-toggle ="popover" data-placement="top"  data-container="body" data-content = "HI" data-trigger = "click" >
                        <td> content 1 </td>
                        <td>content 2</td>
                        <td>content 3 </td>
                    </tr>
                    <tr data-toggle ="popover" data-placement="top"  data-container="body"  data-content = "HI" data-trigger = "click" >
                        <td>content 1 </td>
                        <td>content 2</td>
                        <td>content 3 </td>
                    </tr>
                    </table>
            </div>
  
    </body>