how2j.cn

"); window.frames["iframe_toc"+sid].document.write(decodeHtml($("pre#stepCodePre"+sid).html())); window.frames["iframe_toc"+sid].document.close(); $(window.frames["iframe_toc"+sid]).load(function(){ $("#iframe_toc"+sid).height($("#iframe_toc"+sid).contents().find("body").height()+(showittryitheight)); }); $("#iframe_toc"+sid).height($("#iframe_toc"+sid).contents().find("body").height()+(showittryitheight)); } $("input.tocName").hover(function(){ $(this).select(); }); function refresh(){ var sid = tocstepids.shift(); if(null!=sid) refreshIframe(sid); else go2ArchorFlag = true; } var t = setInterval(refresh,300); // $("div.steptoc iframe").height($(showittryitheight+50)); });
效果 说明 示例代码
<!DOCTYPE html>
<script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script>
<style>
div.well{
  margin:10px;
}
</style>
<a class="btn btn-info" role="button" data-toggle="collapse" href="#dota" aria-expanded="false" aria-controls="collapseExample">
  DotA
</a>
<button class="btn btn-info" type="button" data-toggle="collapse" data-target="#lol" aria-expanded="false" aria-controls="collapseExample">
  LOL
</button>
<div class="collapse" id="dota">
  <div class="well">
《DotA》(Defense of the Ancients),可以译作守护古树、守护遗迹、远古遗迹守卫, 是由暴雪公司出品即时战略游戏《魔兽争霸3》的一款多人即时对战、自定义地图,可支持10个人同时连线游戏,是暴雪公司官方认可的魔兽争霸的RPG地图。
  </div>
</div>

<div class="collapse" id="lol">
  <div class="well">
《英雄联盟》(简称lol)是由美国Riot Games开发,中国大陆地区由腾讯游戏运营的网络游戏。
  </div>
</div>
<div style="height:100px"></div>
基本折叠
示例代码
<!DOCTYPE html>
<script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script>

<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  <div class="panel panel-default">
    <div class="panel-heading" role="tab" id="headingOne">
      <h4 class="panel-title">
        <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
          DOTA
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
      <div class="panel-body">
       《DotA》(Defense of the Ancients),可以译作守护古树、守护遗迹、远古遗迹守卫, 是由暴雪公司出品即时战略游戏《魔兽争霸3》的一款多人即时对战、自定义地图,可支持10个人同时连线游戏,是暴雪公司官方认可的魔兽争霸的RPG地图。
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading" role="tab" id="headingTwo">
      <h4 class="panel-title">
        <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          LOL
        </a>
      </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
      <div class="panel-body">
《英雄联盟》(简称lol)是由美国Riot Games开发,中国大陆地区由腾讯游戏运营的网络游戏。
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading" role="tab" id="headingThree">
      <h4 class="panel-title">
        <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
          风暴英雄
        </a>
      </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
      <div class="panel-body">
       《风暴英雄》 是由暴雪娱乐公司开发的一款运行在Windows和Mac OS上的在线多人竞技PC游戏。
      </div>
    </div>
  </div>
</div>
面板折叠
示例代码
示例 1 : 基本折叠   
示例 2 : 面板折叠   

示例 1 :

基本折叠

基本折叠
"); window.frames["iframe_show3017"].document.write(decodeHtml($("textarea#stepcodeTextarea3017").val())); window.frames["iframe_show3017"].document.close(); $(window.frames["iframe_show3017"]).load(function(){ $("#iframe_show3017").height($("#iframe_show3017").contents().find("body").height()+showittryitheight); }); $("#iframe_show3017").height($("#iframe_show3017").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<!DOCTYPE html> <script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script> <link href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet"> <script src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script> <style> div.well{ margin:10px; } </style> <a class="btn btn-info" role="button" data-toggle="collapse" href="#dota" aria-expanded="false" aria-controls="collapseExample"> DotA </a> <button class="btn btn-info" type="button" data-toggle="collapse" data-target="#lol" aria-expanded="false" aria-controls="collapseExample"> LOL </button> <div class="collapse" id="dota"> <div class="well"> 《DotA》(Defense of the Ancients),可以译作守护古树、守护遗迹、远古遗迹守卫, 是由暴雪公司出品即时战略游戏《魔兽争霸3》的一款多人即时对战、自定义地图,可支持10个人同时连线游戏,是暴雪公司官方认可的魔兽争霸的RPG地图。 </div> </div> <div class="collapse" id="lol"> <div class="well"> 《英雄联盟》(简称lol)是由美国Riot Games开发,中国大陆地区由腾讯游戏运营的网络游戏。 </div> </div> <div style="height:100px"></div>
"); window.frames["iframe3017"].document.write(decodeHtml(code3017)); window.frames["iframe3017"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3017"]).load(function(){ $("#iframe3017").height($("#iframe3017").contents().find("body").height()+showittryitheight); }); $("#iframe3017").height($("#iframe3017").contents().find("body").height()+showittryitheight); alreadyWriteCode3017 = code3017; $("#rendering3017").hide(); $("#rendered3017").show(); } var tRereshRetry2DemoPanel3017 = setInterval(rereshRetry2DemoPanel3017,1000); var binded3017 = false; $("textarea#stepcodeTextarea3017").keyup(function(){ if(!binded3017){ $(window).bind('beforeunload',function(){ binded3017 = true; return "xxxx"; }); } var newCode = $(this).val() code3017 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code3017!=newCode){ // window.frames["iframe3017"].document.write("
"); // window.frames["iframe3017"].document.write(decodeHtml($("textarea#stepcodeTextarea3017").val())); // window.frames["iframe3017"].document.close(); // $(window.frames["iframe3017"]).load(function(){ // $("#iframe3017").height($("#iframe3017").contents().find("body").height()+showittryitheight); // }); // code3017 = newCode; // } }); $(".tryButton3017").click(function(){ $("#tryDiv3017").show(); $("#stepcodeTextarea3017").focus(); $("#stepcodeTextarea3017").height(200); $("#iframe3017").height(0); window.frames["iframe3017"].document.write("
"); window.frames["iframe3017"].document.write(decodeHtml($("textarea#stepcodeTextarea3017").val())); window.frames["iframe3017"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3017"]).load(function(){ $("#iframe3017").height($("#iframe3017").contents().find("body").height()+showittryitheight); }); $("#iframe3017").height($("#iframe3017").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor3017.focus(); editor3017.setSize(null, "250"); $("#rendering3017").hide(); $("#rendered3017").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor3017 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea3017"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor3017.on("change",function(doc){ if(!binded3017){ $(window).bind('beforeunload',function(){ binded3017 = true; return "xxxx"; }); } var newCode = doc.getValue(); code3017 = newCode; $("textarea#stepcodeTextarea3017").val(newCode); if(alreadyWriteCode3017!=code3017){ lastModifedTime3017 = new Date().getTime(); $("#rendering3017").show(); $("#rendered3017").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor3017 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor3017.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv3017").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 2 :

面板折叠

面板折叠
"); window.frames["iframe_show3018"].document.write(decodeHtml($("textarea#stepcodeTextarea3018").val())); window.frames["iframe_show3018"].document.close(); $(window.frames["iframe_show3018"]).load(function(){ $("#iframe_show3018").height($("#iframe_show3018").contents().find("body").height()+showittryitheight); }); $("#iframe_show3018").height($("#iframe_show3018").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<!DOCTYPE html> <script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script> <link href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet"> <script src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script> <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> <div class="panel panel-default"> <div class="panel-heading" role="tab" id="headingOne"> <h4 class="panel-title"> <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> DOTA </a> </h4> </div> <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> <div class="panel-body"> 《DotA》(Defense of the Ancients),可以译作守护古树、守护遗迹、远古遗迹守卫, 是由暴雪公司出品即时战略游戏《魔兽争霸3》的一款多人即时对战、自定义地图,可支持10个人同时连线游戏,是暴雪公司官方认可的魔兽争霸的RPG地图。 </div> </div> </div> <div class="panel panel-default"> <div class="panel-heading" role="tab" id="headingTwo"> <h4 class="panel-title"> <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> LOL </a> </h4> </div> <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo"> <div class="panel-body"> 《英雄联盟》(简称lol)是由美国Riot Games开发,中国大陆地区由腾讯游戏运营的网络游戏。 </div> </div> </div> <div class="panel panel-default"> <div class="panel-heading" role="tab" id="headingThree"> <h4 class="panel-title"> <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree"> 风暴英雄 </a> </h4> </div> <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree"> <div class="panel-body"> 《风暴英雄》 是由暴雪娱乐公司开发的一款运行在Windows和Mac OS上的在线多人竞技PC游戏。 </div> </div> </div> </div>
"); window.frames["iframe3018"].document.write(decodeHtml(code3018)); window.frames["iframe3018"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3018"]).load(function(){ $("#iframe3018").height($("#iframe3018").contents().find("body").height()+showittryitheight); }); $("#iframe3018").height($("#iframe3018").contents().find("body").height()+showittryitheight); alreadyWriteCode3018 = code3018; $("#rendering3018").hide(); $("#rendered3018").show(); } var tRereshRetry2DemoPanel3018 = setInterval(rereshRetry2DemoPanel3018,1000); var binded3018 = false; $("textarea#stepcodeTextarea3018").keyup(function(){ if(!binded3018){ $(window).bind('beforeunload',function(){ binded3018 = true; return "xxxx"; }); } var newCode = $(this).val() code3018 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code3018!=newCode){ // window.frames["iframe3018"].document.write("
"); // window.frames["iframe3018"].document.write(decodeHtml($("textarea#stepcodeTextarea3018").val())); // window.frames["iframe3018"].document.close(); // $(window.frames["iframe3018"]).load(function(){ // $("#iframe3018").height($("#iframe3018").contents().find("body").height()+showittryitheight); // }); // code3018 = newCode; // } }); $(".tryButton3018").click(function(){ $("#tryDiv3018").show(); $("#stepcodeTextarea3018").focus(); $("#stepcodeTextarea3018").height(200); $("#iframe3018").height(0); window.frames["iframe3018"].document.write("
"); window.frames["iframe3018"].document.write(decodeHtml($("textarea#stepcodeTextarea3018").val())); window.frames["iframe3018"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3018"]).load(function(){ $("#iframe3018").height($("#iframe3018").contents().find("body").height()+showittryitheight); }); $("#iframe3018").height($("#iframe3018").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor3018.focus(); editor3018.setSize(null, "250"); $("#rendering3018").hide(); $("#rendered3018").hide(); }); var mixedMode = { name: "htmlmixed", scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, mode: null}, {matches: /(text|application)\/(x-)?vb(a|script)/i, mode: "vbscript"}] }; var editor3018 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea3018"), { lineNumbers: true, styleActiveLine: true, matchBrackets: true, mode:"text/html", theme:"eclipse", selectionPointer: true, lineWrapping: true, extraKeys: { "Alt-/": "autocomplete", "Ctrl-F": "findPersistent", "F8": function(cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); }, "Esc": function(cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); } } }); editor3018.on("change",function(doc){ if(!binded3018){ $(window).bind('beforeunload',function(){ binded3018 = true; return "xxxx"; }); } var newCode = doc.getValue(); code3018 = newCode; $("textarea#stepcodeTextarea3018").val(newCode); if(alreadyWriteCode3018!=code3018){ lastModifedTime3018 = new Date().getTime(); $("#rendering3018").show(); $("#rendered3018").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor3018 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor3018.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv3018").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果


HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


关于 前端部分-BootStrap-折叠 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 620943819
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: http://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图