简体   繁体   English

Twitter Bootstrap工具提示连续显示/隐藏

[英]Twitter Bootstrap Tooltip showing / hiding consecutively

I have an Problem by showing and hiding consecutively a tooltip. 我通过连续显示和隐藏工具提示来解决问题。

Have a look at this snippet: http://jsfiddle.net/r7GCJ/ 看看这个片段: http//jsfiddle.net/r7GCJ/

the input-field shows an tooltip if the number in the tooltip is even.

If you fast triple-click the backspace-key (which means '6' is the last char), you will not see the bootstrap tooltip, even though the number is even. 如果快速三击退格键(这意味着'6'是最后一个字符),即使数字是偶数,也不会看到引导工具提示。 (Maybe you need one or two attempts) (也许你需要一两次尝试)

Anyone an idea how to fix this problem, or whats the problem? 任何人都知道如何解决这个问题,或者问题是什么?

PS: In my 'real code' I have to look up via AJAX if the number is already in a DB, and if so I show the tooltip. PS:在我的“真实代码”中,如果数字已经在数据库中,我必须通过AJAX查找,如果有,我会显示工具提示。

That is a curious issue. 这是一个奇怪的问题。 I have found a solution, although I'll admit it's a bit kludgy. 我找到了一个解决方案,虽然我承认它有点笨拙。 Instead of hiding it, I'm destroying it and recreating it whenever I want to show it. 而不是隐藏它,我正在摧毁它并在我想要显示它时重新创建它。 I can't reproduce the issue in fiddle anymore. 我再也不能在小提琴中重现这个问题了。

$('#fooInput').keyup(function (e) {
    var $foo = $(e.target);
    if (parseInt($foo.val()) % 2 === 0) {
        // create the tooltip
        $foo.tooltip({
            trigger: 'manual',
            title: 'gerade Zahl!',
            placement: 'bottom'
        });
        $foo.tooltip('show');
    } else {
        $foo.tooltip('destroy');
    }
});

FIDDLE 小提琴

Very interesting thing :D. 非常有趣的事情:D。 I don't know why but this is non common situation. 我不知道为什么,但这是不常见的情况。 You can solve this by writing <input id="fooInput" type="text" /> instead of your code with initial value. 您可以通过编写<input id="fooInput" type="text" />而不是具有初始值的代码来解决此问题。 You can add another tooltip to say that only numbers are allowed. 您可以添加另一个工具提示,表示只允许使用数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM