0

我有这样的php条件:

<?php
    if($numResults > 0)
    { ?>
        <button id="unfollow" class="button"> unfollow </button>
<?php }

    else
    { ?>
        <button id="follow" class="button"> follow </button>
<?php } ?>

但如果条件变为“else statement”,我想要一个 jquery 事件处理程序,以便当用户单击“follow”时,按钮淡出,“unfollow”淡入

我试过了,但它只会淡出“关注”按钮,而不会淡出“取消关注”按钮

$('#follow').click(function()
    {
        $("#follow").fadeOut("slow");
        $("#unfollow").fadeIn("slow");

    });

有什么建议么?

4

4 回答 4

0
$('#follow').click(function()
{
    $("#follow").fadeOut("slow",function(){
    $("#follow").text("unfollow").fadeIn("slow");
    });

});
于 2013-10-17T14:57:47.640 回答
0

尝试这个

<?php
    if($numResults > 0)
    { ?>
        <button id="unfollow" class="button"> unfollow </button>
<?php }

    else
    { ?>
        <button id="follow" class="button"> follow </button>
        <button id="unfollow" class="button"> unfollow </button>
        <style>
            #unfollow { display:none;}
        </style>
<?php } ?>

JS

$('#follow').click(function()
    {

        $("#follow").fadeOut("slow");
        $("#unfollow").css("display","block");
        $("#unfollow").fadeIn("slow"); // this may not require if you don't want effect

    });
于 2013-10-17T15:15:03.533 回答
0
<!-- Unfollow button -->
<button id="unfollow" 
        style="display:<?php echo ( $numResults > 0 ? 'none' : 'block' ); ?>"
        class="button">Unfollow</button>

<!-- Follow Button -->
<button id="follow" 
        style="display:<?php echo ( $numResults > 0 ? 'block' : 'none' ); ?>"
        class="button">Follow</button>
于 2013-10-17T14:55:41.213 回答
0

您应该将它们都放在页面上,其中一个最初会淡出。在这里它正在工作。http://jsfiddle.net/TzkGT/

<button id="follow" class="button"> follow </button>
<button id="unfollow" class="button" style="display: none;"> unfollow </button>


$('.button').click(function(){
    $("#follow").fadeToggle("slow");
    $("#unfollow").fadeToggle("slow");
});
于 2013-10-17T14:56:15.730 回答