Twitter引导程序:Popop在第一次点击时没有显示,但在第二次点击时显示

时间:2014-04-20 13:00:05

标签: javascript twitter-bootstrap popup

这是我的代码。请帮帮我

$(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");
});

});

2 个答案:

答案 0 :(得分:0)

尝试用.on()替换.delegate()函数,此函数已在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");
});

});

答案 1 :(得分:0)

尝试这样做..

$('.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');
    }
});
相关问题