jQuery切换文本? [英] jQuery Toggle Text?

查看:91
本文介绍了jQuery切换文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何使用jQuery在锚标记的html文本之间切换文本.我想要一个锚点,当单击该锚点时,文本会在显示背景"和"显示文字"以及在&中逐渐消失出另一个div.这是我最好的猜测:

Does anybody know how to toggle text the html text of an anchor tag using jQuery. I want an anchor that when clicked the text alternates between "Show Background" & "Show Text" as well as fading in & out another div. This was my best guess:

$(function() {
    $("#show-background").click(function () {
        $("#content-area").animate({opacity: 'toggle'}, 'slow'); 
    });

    $("#show-background").toggle(function (){
        $(this).text("Show Background")
        .stop();
    }, function(){
        $(this).text("Show Text")
        .stop();
    });
});

谢谢.

推荐答案

抱歉,问题出在我身上!这是不同步的,但这是因为我的HTML文本处理方式错误.第一次单击时,我希望div消失,并显示显示文本"文字.

Sorry the problem is me! the was out of sync but this was because I have the HTML text the wrong way around. On the first click I want the div to fade out and the text to say "Show Text".

下次我问之前将进行更彻底的检查!

Will check more thoroughly next time before I ask!

我的代码现在是:

$(function() {
  $("#show-background").toggle(function (){
    $("#content-area").animate({opacity: '0'}, 'slow')
    $("#show-background").text("Show Text")
      .stop();
  }, function(){
    $("#content-area").animate({opacity: '1'}, 'slow')
    $("#show-background").text("Show Background")
      .stop();
  });
});

再次感谢您的帮助!

这篇关于jQuery切换文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆