点击单个按钮打开2个弹出窗口

时间:2015-05-26 07:14:17

标签: javascript jquery html twitter-bootstrap

// HTML

li

在这段代码中我有onclick函数,按钮的html部分,如果我点击removeuser按钮,我还有一个相同配置的按钮,即使popover正在打开

2 个答案:

答案 0 :(得分:1)

原因是button都有

data-toggle="popover"

因此两个弹出窗口都会打开。

取而代之的是id$(this)

$('#adduserteam').click(function(){
   $(this).popover('show');
})
$('#removeuserteam').click(function(){
   $(this).popover('show');
})

更新问题后:

$('#removeuserteam').on('click',function() {
    var $this = $(this);
    if(teamuser.rows('.selected').data().length > 0){   
        $.ajax({
                    url : "../../rest/teamRest/removeFromTeam",
                    type : "POST",
                    dataType : "json",
                    contentType : "application/json",
                    data:       JSON.stringify(test.emp),
                    success : function(data) {
                            teamuser.ajax.reload();
                            alert("success deleteRule: ");
                            $('#addteammodal').modal('hide');
                            },
                            error : function(request,status,error) {
                                    teamuser.ajax.reload();
                                    alert("error deleteRule: ");
                                }
                                });
                                $('.edit').removeClass('edit');
                        }
                        else
                            $this.popover('show');

                });

答案 1 :(得分:0)

开箱即用:

实例:http://jsbin.com/sanonu/1/edit?html,js,output

点击事件中的某些内容可能触发第二个...但是,我个人会将触发器更改over而不是click/focus,因此作为用户体验,您将一键点击没有两个动作...

如果你不能,只需使用工具提示而不是 Popover

相关问题