我有一個div:jQuery的顯示()和隱藏()
<div class="showHide">
//content
</div>
和一個按鈕
<button id="event" class="show" type="button">Show more news</button>
CSS是:
.showHide {
display: none;
}
這裏的jQuery:
function show() {
$(".show").click(function(){
$(".hideShow").show(500,'linear');
$(".show").replaceWith('<button id="event" class="hide" type="button">Show less news</button>');
});
}
function hide() {
$(".hide").click(function(){
$(".hideShow").hide(500, 'linear');
$(".hide").replaceWith('<button id="event" class="show" type="button">Show more news</button>');
});
}
$(document).ready(function() {
show();
hide();
});
當我第一次點擊腳本顯示div並替換按鈕,但當我第二次點擊隱藏腳本不起作用..任何幫助?
wooow!有用!!非常感謝你..可能我需要學習一些JavaScript! :) –
我看到一個錯誤...當內容被隱藏時,按鈕的文本不會改變..它仍然是「顯示較少的消息」...我替換了按鈕文本放置一個if如果控制文本並更改它在case..it工程... –