toggle()函数的应用。
以下两种方法显示的效果是一样的:
function addItem0() {
$('#btn_show').toggle(function(){
$('#show_box').show();
$(this).html('点击收缩');
},function(){
$('#show_box').hide();
$(this).html('点击弹开');
})
};
<div class="box">
<a href="#" id="btn_show" style=" display: block;">点击弹开</a>
<div id="show_box" style="display: none;">show_boxshow_boxshow_boxshow_boxshow_box</div>
$(function(){
$('#bn').toggle(function(){
$(this).next('div.content').toggle();
},function(){
$(this).next('div.content').toggle();
});
})
<div id="bn">ddff</div>
<div class="content">contentcontentcontentcontentcontentcontent</div>