qTip show/hide tooltip on click

霸气de小男生 提交于 2019-12-10 10:34:19

问题


I have a page with many tooltips. I want to show/hide every one seperatly on clicking a button. It does not work for me, can anyone help?

<span><input type="button" value="b1" onClick="showMyTT('div1');"></span><span><div id="div1"></div></span>
<span><input type="button" value="b2" onClick="showMyTT('div2');"></span><span><div id="div2"></div></span>
<span><input type="button" value="b3" onClick="showMyTT('div3');"></span><span><div id="div3"></div>​</span>

function showMyTT(id) { 
    $('#'+id).qtip({
        content: {
            text: 'Show the content', 
            title: false
        },
        position: {
            my: 'left center', 
            at: 'left center' 
        },
        show: {
            event: false, 
            ready: true 
        },
        hide: false, 
        style: {
            classes: 'ui-tooltip-shadow ui-tooltip-jtools'
        }
    }); 
}

Thank you


回答1:


This showMyTT function initializes your tooltips. After running this function for all ids (initialization) you should do something like this:

HTML

<input type="button" value="b1" onClick="toggleQtip('div1');" />

JavaScript

function toggleQtip(id) {
    var div = $('#'+id);
    if (div.data('visible')) {
        div.qtip('hide');
        div.data('visible', false);
    } else {       
        div.qtip('show');
        div.data('visible', true);
    }
}

EDIT

Here's how you can initialize qtip (at least one possibility). Add custom class to all divs you'd like to have a qtip, for example qtiped:

HTML

<div id="div1" class="qtiped">TEST</div>
<input type="button" value="b1" onClick="toggleQtip('div1');" />

and then run the following code:

JavaScript

$(document).ready(function() {
    $('.qtiped').each(function() {
        showMyTT( $(this).attr('id') );
    });
});

Also, inside showMyTT do the following change: show: false in order to avoid autoloading (we want to initialize tooltips, not show them).



来源:https://stackoverflow.com/questions/10030230/qtip-show-hide-tooltip-on-click

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!