简体   繁体   English

如何在切换类中显示不同的工具提示文本

[英]How to show different tooltip text at toggle class

I've a "Show" button. 我有一个“显示”按钮。 When user click on that button, a hidden div will appear and that show button convert to "Hide" button. 当用户单击该按钮时,将显示一个隐藏的div,并且该显示按钮转换为“隐藏”按钮。 At the time of hover on "Show" button icon, a tooltip wil come that say: "Show All". 将鼠标悬停在“显示”按钮图标上时,会显示一个工具提示:“显示全部”。 Now, I need, when that "Show" button icon convert to "Hide" button icon, tooltip text will also converted into "Hide All" . 现在, 我需要将“显示”按钮图标转换为“隐藏”按钮图标时,工具提示文本也将转换为“全部隐藏” How can I make this? 我该怎么做? Here is my fiddle work 这是我的小提琴作品

$('.show').click(function() {
    $(".text").toggle();
    $(this).toggleClass('hide');
})
var toggleState = false;

$('.show').click(function() {
    $('.text').toggle();
    $(this).toggleClass('hide').attr('title', toggleState ? 'Show All' : 'Hide All');
    toggleState = !toggleState;
});

This swaps toggleState boolean to true and false each click. 这样toggleState布尔值切换为true和false。 So first time it is false so it sets title to 'Hide All'. 因此,第一次是错误的,因此将标题设置为“全部隐藏”。 Next time it is true so it sets to 'Show All'. 下次是真的,因此将其设置为“显示全部”。 And so on. 等等。

Fiddle: http://jsfiddle.net/y8ZTj/1/ 小提琴: http : //jsfiddle.net/y8ZTj/1/

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

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