基於BootStrap的Collapse折疊(包含回顯展開折疊的對應狀態)


情況描述:為了改善頁面上的input框太多,采用∧∨折疊展開,這個小東西來控制,第一次做,記錄一下ヾ(◍°∇°◍)ノ゙下邊是Code

代碼:

//html代碼
<div id="collapseTwo" class="panel-collapse collapse"> //想要被折疊起來的代碼 //就使勁往這里放 //就對了 </div>
<div class="col-md-1" style="float: right; margin-top: 2px">
<div data-toggle="collapse" data-parent="#accordion" onclick="clickCollapse()"
href="#collapseTwo">
<div id="open">
<img th:src="@{/assets-new/apps/img/zhankai.png}" title="展開"/><a>展開</a>
</div>
<div id="close" hidden="hidden">
<img th:src="@{/assets-new/apps/img/shouqi.png}" title="關閉"/><a>收起</a>
</div>
</div>
</div>
//js代碼
<script type="text/javascript">
 function clickCollapse() {
$('#open').toggle("fast");
$('#close').toggle("fast");
}
</script>

 

//js代碼 根據折疊展開狀態,頁面回顯與之對應的狀態(發送異步請求時候)
$("#search").click("click", function () {
var state = $('#collapseTwo').hasClass('in');
var url = rootPath + "vrx/vouxxXxx/list";
if (state == true) {
url += "?panelState=open"
} else {
url += "?panelState=close"
}
$("#searchForm").ajaxSubmit({
url: url,
async: true,
success: function (data) {
var tb = $("#loadhtml");
var topliHtml = $("#topli").html();
tb.html(CommnUtil.loadingImg());
tb.html(data);
$("#topli").html(topliHtml);
}
});
});
//后台java
String state = this.getRequest().getParameter("panelState");
map.addAttribute("state",state);
return VIEW_PATH + "/list";
//list.html頁面里的js
<script type="text/javascript" th:inline="javascript" xmlns:th="http://www.w3.org/1999/xhtml">
var state = [[${state}]];
if (CommnUtil.notNull(state)) {
if (state == "open") {
$('#collapseTwo').collapse('show');
$('#open').toggle("fast");
$('#close').toggle("fast");
}
}
</script>
 

 

說明:就這么多代碼,說實話,關於引入的js什么的我還是不太會找正確的好用的鏈接Σ(☉▽☉"a喪!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM