2

I am using Twitter Bootstrap v3 to add a 'Invalid login' tooltip to the login button. Here's my code:

    $('#login-form').submit(function(event) {
        event.preventDefault();
        $.post('/user/login', $(this).serialize(), function(data) {
            if (data.result == true) {
                window.location.replace('/');
            } else {
                var target = $('#login-form button[type="submit"]');
                target.tooltip({
                    title:      'Invalid login',
                    placement:  'bottom',
                    trigger:    'manual',
                    animation:  true
                });
                target.tooltip('show');
                setTimeout(function() {
                    target.tooltip('destroy');
                }, 2000);
            }
        }, 'json')
    });

In particular, I am wondering if there is a better way to close the tooltip. I was hoping that I could configure the tooltip plugin to automatically fade after a few seconds. Alternatively, I tried chaining a .fade(2000) after the call to the 'show' method, but this didn't work.

The above code works, I'm just looking for a more elegant alternative.

4

1 回答 1

1

您可以尝试在工具提示初始化时设置参数“延迟”

像下面的代码

            target.tooltip({
                title:      'Invalid login',
                placement:  'bottom',
                trigger:    'manual',
                animation:  true,
                delay: { show: 2000, hide: 3000 }
            });
于 2014-04-27T05:07:15.670 回答