2016-12-02 41 views
1

我知道这个问题之前已经被问过了,我已经阅读了答案,实现了它,但是我面临着一个小问题。如何通过PHP填充Bootstrap弹出窗口

在PHP文件中,我试图制作一个锚定标记,然后将其显示在弹出窗口中,但是使其变为可点击的,将显示整个内容(以及锚点标记)。另外,一旦图标被点击,即使点击图标或页面上的任何其他位置,图标也会一直存在并且不会消失。

下面是代码:

HTML文件:

<li style="margin-left: 15px;"> 

    <a href="#" data-placement="bottom" title="notifications" data-poload="notification_list.php" id="id-wala"> 
    <img src="assets/ring.png" width="25" height="25" data-toggle="tooltip" data-placement="bottom" title="notifications"> 

    </a> 

    </li> 

AJAX代码

$('*[data-poload]').click(function() { 
      console.log('Hey'); 
     var e=$(this); 
     e.off('click'); 
     e.unbind('click') 
     $.get(e.data('poload'),function(d) { 
      console.log(d); 
      e.popover({content: d}).popover('show'); 
     }); 
    }); 

PHP文件

<?php 
      #The code for connecting to the database removed for clarity. 
      $sql1 = "SELECT PID from post where UID = '$a'"; 
      $result1 = mysqli_query($conn,$sql1); 
      $end_result = ''; 
      while($row1 = mysqli_fetch_assoc($result1)) { 
      $temp = $row1["PID"]; 
      $sql = "SELECT * from comment where status = 'unread' and PID = '$temp' "; 
      $result = mysqli_query($conn, $sql); 
      if (mysqli_num_rows($result) > 0) { 
        while($row = mysqli_fetch_assoc($result)) { 
         $end_result='<a href ="#" >'.'Notification from '.$row["UID"].'</a>'; 
         echo $end_result; 
         echo '<br/>'; 
        } 
      } 
     } 
      $conn->close(); 
    ?> 

的问题是,回声$ END_RESULT从89打印的<a href ="#" >Notification from 89</a>代替通知并使其点击。

请提供一些关于如何解决此问题的建议。

回答

1

问题是因为默认情况下,弹出窗口上的html属性为false。这意味着您尝试放入弹出窗口内容的任何HTML都将被删除。要更改此行为,您需要设置html: true

您还需要使用trigger: 'manual'并使用toggle选项来隐藏/显示连续点击中的弹出窗口。试试这个:

e.popover({ 
    html: true, 
    trigger: 'manual', 
    content: d 
}).popover('toggle'); 

Working example

Bootstrap Popover documentation

+0

非常感谢,它解决了这个问题,只是多了一个thing.How我禁用它再次点击它? – ssharma

+0

我不确定你的意思 - 你想禁用什么? –

+0

我的意思是如果我第二次点击图像,我该如何让popover消失? – ssharma

相关问题