【问题标题】:Set twitter bootstrap popover to hide after a certain event then show after another event将 twitter bootstrap popover 设置为在某个事件后隐藏,然后在另一个事件后显示
【发布时间】:2013-11-22 05:15:33
【问题描述】:

用户在文本区域中进行了更改。当发生这种变化并且另一个条件为真时(在这种特殊情况下,条件是文本字段包含“是”),我将显示一个引导弹出窗口。

showPopover = function() {
    return $(this).popover("show");
};
  hidePopover = function() {
    return $(this).popover("hide");
};

var cond = true;
$("textarea").on("change keyup", function (e) {
    var pt = $("#user_user_profile_attributes_title").val();
    if (cond&&pt=="yes") {
        $("[rel=next-popover]").popover({
        placement: "right",
        trigger: "manual"
    })
    .hover(showPopover, hidePopover).click(showPopover);
    }
    else {
        $("[rel=next-popover]").popover({
        placement: "right",
        trigger: "manual"
    })
    .hover(hidePopover, hidePopover).click(hidePopover);
    }
}); 

重现步骤: 1) 转至http://jsfiddle.net/bpjavascript/KscL5/ 2)在文本字段中输入yes 3)在文本区域中进行更改并在单击/悬停时查看弹出框 4)将“是”更改为其他内容并在文本字段中进行更改,没有弹出框 5) 将文本字段更改回是并在文本字段中进行更改 - 现在您应该会看到一个简短的弹出框闪烁。为什么是这样?我希望它显示在第 3 步中。

【问题讨论】:

    标签: javascript jquery twitter-bootstrap


    【解决方案1】:

    您正在将多个相同类型的事件绑定到弹出框。

    相反,在您的条件逻辑中,如果满足条件,您应该绑定一个事件,否则取消绑定该事件。

    所以在你的else 声明中你应该有类似的内容:

    else {
        $("[rel=next-popover]").popover({
        placement: "right",
        trigger: "manual"
        })
        .off( "mouseenter mouseleave" ).off("click");
    }
    

    Fiddle here.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多