【问题标题】:Twitter bootstrap:Popop are not showing up on first click but show up on second clickTwitter bootstrap:Popop 在第一次点击时不显示,但在第二次点击时显示
【发布时间】:2014-06-04 15:39:06
【问题描述】:
这是我的代码。请帮帮我
$(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");
});
});
【问题讨论】:
标签:
javascript
twitter-bootstrap
popup
【解决方案1】:
尝试用 .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");
});
});
【解决方案2】:
尝试这样做..
$('.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');
}
});