2017-02-24 56 views
2

我有數據,當我點擊Show More它顯示數據和Show More消失。數據和一個新按鈕出現。當我點擊時,數據再次消失。一旦被點擊,我怎樣才能讓Show More出現?如何使用Jquery使按鈕消失然後reapear?

我的HTML代碼爲:

<button id="show">Show More</button> 
<div id="complete"> 
    <img src="Pictures/xerox.png" height="20%" width="20%"> 
</div> 
<p> 
<button id="hide">Show Less</button> 

我jQuery代碼是:

$(document).ready(function(){ 
    $("#show").click(function(){ 
     $(this).parent().addClass("more"); 
     $(this).hide(); 
     $("#complete").show(); 
    }); 

    $("#hide").click(function(){ 
     $("#complete").hide(); 
    }); 
}); 
+0

什麼是感謝你,沒有工作。 :) –

回答

0

它看起來像你的jQuery告訴對象進行調用來隱藏自身單擊時:

$(this).hide(); 

根據您的描述,我建議您將以下內容添加到處理Show Les的函數中S功能:

$('#show').show(); 
0

我從這個問題的理解是你想

<style> 
#complete{ 
display:none; 
} 
#hide{ 
display:none; 
} 
</style> 

<button id="show">Show More</button> 
<div id="complete"> 
<img src="Pictures/xerox.png" height="20%" width="20%"> 
</div> 
<p> 
<button id="hide">Show Less</button> 


<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> 

<script> 
$(document).ready(function(){ 
    $("#show").click(function(){ 
     $(this).parent().addClass("more"); 
     $(this).hide(); 
     $("#hide").show(); 
     $("#complete").show(); 
    }); 

    $("#hide").click(function(){ 
     $("#complete").hide(); 
     $("#show").show(); 
     $("#hide").hide(); 
    }); 
}); 
</script> 
+0

複製並粘貼到瀏覽器中,你會看到你想要的行爲 –