qTip2 - 更改工具提示的内容后调用函数

问题描述 投票:0回答:1

我有一个qTip工具提示,我通过ajax加载其内容。加载内容后我需要调用函数someFunction()

$('.element').qtip(
{
    content: 
    {
        text: function(event, api) 
        {
            api.elements.content.text('Loading...');

            var content = $.ajax(
            {
                url: 'loadcontent.php',
                dataType: 'json'
            })
            .then(function(result) 
            {
                // Some code for changing result html
                return result.html;

            }, function(xhr, status, error) 
            {
                api.set('content.text', 'Error');
            });

            // Calling a function, but it's too early (content is still not in the tooltip)
            someFunction();

            return content;
        }
    }
});

说实话,我不知道在哪里放置someFunction(),所以在将内容添加到工具提示后调用它。更改内容后没有触发事件。

javascript jquery qtip2
1个回答
0
投票

我提出了一个解决方案:

$('.element').qtip(
{
    content: 
    {
        text: 'Loading...'
    },
    events: 
    {
        show: function(event, api) 
        {
            $.ajax(
            {
                url: 'loadcontent.php',
                dataType: 'json'
            })
            .then(function(result) 
            {
                api.set('content.text', result.html);

                someFunction();

            }, function(xhr, status, error) 
            {
                api.set('content.text', 'Error');
            });
        }
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.