2016-12-25 28 views

回答

1

更改你的JS函数像下面将工作

$(function() { 
    $(".expand").on("click", function() { 
    $(".expand").find(">:first-child").text("+"); 
    $(".detail").css("display","none"); 
    $(this).next().slideToggle(200); 
    $expand = $(this).find(">:first-child"); 

    if($expand.text() == "+") { 
     $expand.text("-"); 
    } else { 
     $expand.text("+"); 
    } 
    }); 
}); 

找到这个fiddle

0

这个替换您的javascript:

$(function() { 
    $(".expand").on("click", function() { 
    if($(this).next().css("display")=="none"){ 
     $(".expand").next().css("display","none"); 
     $expandold = $(".expand").find(">:first-child"); 
     $expandold.text("+"); 
     $(this).next().slideToggle(200); 
     $expand = $(this).find(">:first-child"); 
     $expand.text("-"); 
    } 
    else{ 
     $(".expand").next().css("display","none"); 
     $expand = $(this).find(">:first-child"); 
     $expand.text("+"); 
    } 

    }); 
}); 

这里的工作codepen

+0

@Honeybeemy试试这个 – ab29007

0

这将是使用效果基本show方法的解决方案。

$(function() { 
    $(".expand").on("click", function() { 
    $('.detail').not($(this).next()).slideUp().prev().find(">:first-child").each(function(){ 
     $(this).text("+"); 
    }); 

    $(this).next().slideToggle(200); 
    $expand = $(this).find(">:first-child"); 

    if($expand.text() == "+") { 
     $expand.text("-"); 
    } else { 
     $expand.text("+"); 
    } 
    }); 
}); 
相关问题