JS 展开关闭功能代码

<script>
jQuery( document ).ready( function ( $ ) {
$( '#control' ).click( function () {
if ( $( '#control a' ).is( '#hide-sidebar' ) ) {
$( '#sidebar' ).hide();
$( '#control' ).attr( "class", "hide" );
$( '#content' ).removeClass( "left-width" );
$( "#content" ).addClass( "full-width" );
$( '#control a' ).attr( "id", "show-sidebar" ).attr( "title", "显示边栏" ).text( "显示边栏" );
} else if ( $( '#control a' ).is( '#show-sidebar' ) ) {
$( '#sidebar' ).show();
$( '#control' ).attr( "class", "show" );
$( "#content" ).removeClass( "full-width" );
$( "#content" ).addClass( "left-width" );
$( '#control a' ).attr( "id", "hide-sidebar" ).attr( "title", "隐藏边栏" ).text( "隐藏边栏" );
}
} )
} );
</script>

<span id="control" class="show"><a style="cursor:pointer;" id="hide-sidebar" title="隐藏边栏">隐藏边栏</a></span>
<div id="sidebar" class="right"></div>
<div id="content" class="left-width"></div>

发表评论

电子邮件地址不会被公开。 必填项已用*标注