我有一个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工程... –