我有一些引导按钮,单击按钮时应该显示一个弹出框。
usernameL.onclick = function(e){
$("#" + e.currentTarget.id).popover({html : true});
}
当网站加载完毕并且我第一次单击该按钮时,什么也没有发生。如果我再次单击,弹出框会打开并且可以正常工作。
我该怎么做才能在第一次点击时出现弹出框?
我有一些引导按钮,单击按钮时应该显示一个弹出框。
usernameL.onclick = function(e){
$("#" + e.currentTarget.id).popover({html : true});
}
当网站加载完毕并且我第一次单击该按钮时,什么也没有发生。如果我再次单击,弹出框会打开并且可以正常工作。
我该怎么做才能在第一次点击时出现弹出框?
那这个呢?
usernameL.onclick = function(e){
$("#" + e.currentTarget.id).popover({html : true}).popover('show');
}
在您的代码中,第一次单击按钮时弹出框仅开始初始化,因此直到第二次单击,您才会看到效果,
我不确定您使用的版本弹出框。作为我找到的资源,他们也在使用 jquery。
https://github.com/klaas4/jQuery.popover/blob/master/demo.html
您可以先初始化弹出框,然后从您想要的任何按钮触发点击第一种方法,将弹出框直接绑定到按钮
$(function(){
$("[name=usernameL]").popover({trigger: 'click'});
});
第二个方法,从内容 div 绑定弹出窗口,并通过单击按钮显示弹出窗口
$("#divcontent").popover({trigger: 'click'});
$("[name=usernameL]").click(function(){$("#divcontent").trigger('click')});
try this
usernameL.onclick = function(e){
$("#" + e.currentTarget.id).popover({html : true});//Initializes popover
$("#" + e.currentTarget.id).popover('show');//show popover
}
试试jquery风格,
我想按钮是 id usernameL
$('#usernameL').click(function(){
$(this).popover();
});