推特引导:Popop不会在第一次点击时出现,但会在第二次点击时显示

Twitter bootstrap:Popop are not showing up on first click but show up on second click

本文关键字:显示 第二次 第一次 Popop      更新时间:2023-09-26

这是我的代码。请帮我

$(document).ready(function(){
$(document).delegate(".view","click",function(){
    var id = $(this).attr("id");
    alert(id);
    $("#"+id).popover({
        html : true, 
        content: function() {
          return $("#"+id+"tt").html();
        },
        title: function() {
            return $('#popoverTitle').html();
        }
    });
    alert("thisa");
});

});

尝试将函数.delete()替换为.on(),此函数在Jquery的最新版本中已被取代。

jQuery 1.4.3+

$( elements ).delegate( selector, events, data, handler );

jQuery 1.7+

$( elements ).on( events, selector, data, handler );

代码是:

$(document).ready(function(){
$(document).on("click",".view",function(){
    var id = $(this).attr("id");
    alert(id);
    $("#"+id).popover({
        html : true, 
        content: function() {
          return $("#"+id+"tt").html();
        },
        title: function() {
            return $('#popoverTitle').html();
        }
    });
    alert("thisa");
});
});

尝试这样做。。

$('.view')
.popover({trigger: 'manual'})
    .click(function() {
    if($(this).hasClass('pop')) {
        $(this)
        .popover('hide')
        .removeClass('pop');
    } else {
        var id = $(this).attr("id");
        var title = $('#popoverTitle').html();
        var response = $("#"+id+"tt").html();
        $(this)
        .attr({'title': title, 'data-content': response})
        .popover('show')
        .addClass('pop');
    }
});