在使用ajax處理懸停事件時,引導彈窗不會第一次出現

[英]Bootstrap popover doesn't appear the first time on hover event using ajax


The appropriate bits of what I tried are here:

我嘗試過的一些適當的方法如下:

$(".popovers").mouseover( function()
{
    //var mainTableBody = document.getElementById("subCriteriaTableBody");
    var tableRows = document.getElementsByClassName("popoversBlock");
    var i = 0, j = 0;
    for (i = 0; i < tableRows.length; i++) 
    {
        var labelList = tableRows[i].getElementsByTagName("label");             
        var tdList = tableRows[i].getElementsByClassName("popovers");               
        for (j = 0; j < labelList.length; j++) 
        {
            if(labelList[j].parentElement.parentElement.rowIndex == tdList[j].parentElement.rowIndex) 
            {   
                attName = $(this).text();   
                var attributeName = attName.slice(0, -1);   
                $.ajax({
                    url:'/diganta/getPopoverValueReassignTaskOfUser.do?attributeName='+attributeName,  
                    type:'post',  
                    dataType: 'json',  
                    success: function(data) {
                        $('.popovers').attr('data-content', data.PopoverValue); 
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert("Failed! Reason: "+ thrownError);
                    }
                });
                break;
            } 
            else 
            {
                continue;
            }
        }
    }
});

When I mouse hover, I see the request get made, but doesn't populate the popover. I don't even see JSP page for the popover first time but second time it's ok get added to the DOM.

當我鼠標懸停時,我看到請求被發出,但是沒有填充彈出窗口。我甚至沒有第一次看到彈出窗口的JSP頁面,但是第二次添加到DOM是可以的。

Please help me .... Thanks in advance.

請幫我....提前謝謝。

2 个解决方案

#1


1  

You need to call

你需要打電話

$('.popovers').attr('data-content', data.PopoverValue).popover('show');

to show the Popover

顯示彈出窗口

Hope it will solve your problem...

希望它能解決你的問題……

Edit

編輯

$('#your_lable_id').attr('data-content', data.PopoverValue).popover('show');

#2


1  

If the problem appears at the first time only and it works afterwards, you are probably missing:

如果這個問題只在第一次出現,之后才出現,那么你很可能會錯過:

$(document).ready(function(){
   ...
});

Another advice, quoting W3C page:

另一個建議,引用W3C頁面:

Popovers are not CSS-only plugins, and must therefore be initialized with jQuery: select the specified element and call the popover() method.

彈窗不是僅用於css的插件,因此必須使用jQuery初始化:選擇指定的元素並調用彈窗()方法。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/05/30/724d628020d54532c3e97eac03083e37.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com