我的jQuery if / else语句我做错了什么?

时间:2013-06-16 03:12:49

标签: javascript jquery if-statement

我知道我的HTML很好,但是如何将这个if if语句。我希望文本消失,按钮文本改变,然后再按一下按钮反转。

这是我的代码:

    $("#disappearingButton").click(function(){

    if($("#thePara").is(":hidden")){
        $("#thePara").show();
        $("#disappearingButton").html("Click to disappear");
    }else{
        $("#thePara").hide();
        $("#disappearingButton").html("Click to reappear");
    }
});

2 个答案:

答案 0 :(得分:0)

if(!$("#thePara").is(":visible")){

if ($("#thePara").css("display") == "none"){

答案 1 :(得分:0)

试试这个js fiddle

$(document).ready(function(){
    $("#disappearingButton").click(function(){
        $('#btheParaook').toggle(function(){
            $('#disappearingButton').text('click to appear');
        } );
    });
}); 
相关问题