解决方法
使用bootstrap响应类和两个jquery onclick事件的示例:
http://bootply.com/62828
HTML
<div class="container"> <div class="row"> <div class="span9" id="content" style="background-color:blue;"> <div class="navbar visible-phone"> <div class="container"> <a class="btn btn-navbar" id="showsidebar"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> </div> </div> <p>Main column</p> <p>Content...</p> </div> <div class="span3 hidden-phone" id="sidebar" style="background-color:darkgreen;"> <div class="navbar visible-phone"> <div class="container"> <a class="btn btn-navbar" id="showcontent"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> </div> </div> Sidebar </div> </div> </div>
JavaScript的
$('#showsidebar').click(function(){ $('#sidebar').removeClass('hidden-phone'); $('#content').addClass('hidden-phone'); } ); $('#showcontent').click(function(){ $('#sidebar').addClass('hidden-phone'); $('#content').removeClass('hidden-phone'); } );