将引导程序弹出窗口配置为仅出现一次? [英] Configuring a bootstrap popover to appear only once?

查看:69
本文介绍了将引导程序弹出窗口配置为仅出现一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Bootstrap .popover()在输入字段与预期格式不匹配时显示通知.我认为直接杀死hidden.bs.popover事件中的弹出窗口很容易,但是这样做会使我陷入一个递归循环中,并显示错误消息:

I'm using a Bootstrap .popover() to display a notification whenever an input field does not match the expected format. I thought it would be straight forward to kill the popover in the hidden.bs.popover event, but doing so lands me in a recursion loop with the error reading:

error (firebug): 
  too much recursion

line 4985 in wordpress/wp-includes/js/jquery/jquery.js?ver=1.10.2
    for ( ; cur; cur = cur.parentNode ) {

我尝试从事件处理程序返回false并调用.preventDefault().我可以看到为什么这是一种错误的方法,并且会在显示并关闭一次该.popover之后要求提供有关如何彻底销毁该.popover的建议.

I tried returning false from the event handler as well as calling .preventDefault(). I can see why that's a wrong approach, and would ask for suggestions on how to cleanly destroy the .popover after it has been shown and closed one time.

invalid_regex_input.popover({ 
    placement: 'top',
    title: 'Invalid  input', 
    content: 'Please type in a valid value'
})
.on('hidden.bs.popover', function (e) {
    //console.log('destroy', e);
    //e.preventDefault();

    $(this).popover('destroy');

    //return false;
})
.popover('show');

推荐答案

根据文档,销毁通话隐藏:

.popover('destroy')
Hides and destroys an element's popover.

您可以尝试在其事件处理程序中取消注册hidden.bs.popover,然后在其中调用destroy并将其重新附加到show事件中.这不一定是干净的编码,但是可以完成工作,并且在我看来是可以接受的.

You could try to unregister the hidden.bs.popover inside its event handler, before calling destroy there, and reattach it in the show event. This isn't necessarily clean coding, but it'll get the job done and is acceptable in my opinion.

类似(伪代码)的

function onPopoverHidden(ev) {
    // Unregister self, by calling .off('hidden.bs.popover') on the popover object
    // Then, call .popover('destroy') on it.
}

.on('show.bs.popover', function() {
    // (re-)attach onPopoverHidden event handler function
})
.on('hidden.bs.popover', onPopoverHidden);

invalid_regex_input.popover({/* settings */})
.on('hidden.bs.popover', function (e) {
    $(this).off('hidden.bs.popover');
    $(this).popover('destroy');
 })

这篇关于将引导程序弹出窗口配置为仅出现一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆