jQuery Easyui實現(xiàn)左右布局
EasyUI 簡介
easyui是一種基于jQuery的用戶界面插件集合。
easyui為創(chuàng)建現(xiàn)代化,互動,JavaScript應(yīng)用程序,提供必要的功能。
使用easyui你不需要寫很多代碼,你只需要通過編寫一些簡單HTML標記,就可以定義用戶界面。
easyui是個完美支持HTML5網(wǎng)頁的完整框架。
easyui節(jié)省您網(wǎng)頁開發(fā)的時間和規(guī)模。
easyui很簡單但功能強大的。
在后臺管理系統(tǒng)開發(fā)的過程中,上左右的布局是最常見的頁面布局方式,現(xiàn)在我們來看看使用easyui這個jquery前端框架如何快速搭建一個可用的頁面框架。
1.在頁面中引入easyui所需的文件
<%-- 加載easyui的樣式文件,bootstrap風格 --%>
<link href="${ctx }/css/themes/bootstrap/easyui.css" rel="stylesheet">
<link href="${ctx }/css/themes/icon.css" rel="stylesheet">
<%-- 加載jquery和easyui的腳本文件 --%>
<script src="${ctx }/js/jquery-easyui-../jquery.min.js"></script>
<script src="${ctx }/js/jquery-easyui-../jquery.easyui.min.js"></script>
<script src="${ctx }/js/jquery-easyui-../locale/easyui-lang-zh_CN.js"></script>
2.在頁面body部分構(gòu)建必要的html結(jié)構(gòu)
<body> <div id="home-layout"> <!-- 頁面北部,頁面標題 --> <div data-options="region:'north'" style="height:50px;"> <!-- add your code --> </div> <!-- 頁面西部,菜單 --> <div data-options="region:'west',title:'菜單欄'" style="width:200px;"> <div class="home-west"> <ul id="home-west-tree"></ul> </div> </div> <!-- 頁面中部,主要內(nèi)容 --> <div data-options="region:'center'"> <div id="home-tabs"> <div title="首頁"> <h2 style="text-align: center">歡迎登錄</h2> </div> </div> </div> </div> </body>
這里需要注意一點:easyui在使用layout布局的時候,north、south需要指定高度,west、east需要指定寬度,而center會自動適應(yīng)高和寬。
3.使用js初始化easyui組件
我個人比較推薦使用js代碼去初始化easyui組件,而不使用easyui標簽中的data-options屬性去初始化。因為對于后臺開發(fā)人員來說,寫js代碼可能比寫html標簽更加熟悉,而且這樣使得html代碼更加簡潔。
<script>
$(function(){
/*
* 初始化layout
*/
$("#home-layout").layout({
//使layout自適應(yīng)容器
fit: true
});
/*
* 獲取左側(cè)菜單樹,并為其節(jié)點指定單擊事件
*/
$("#home-west-tree").tree({
//加載菜單的數(shù)據(jù),必需
url: "${ctx }/pages/home-west-tree.json",
method: "get",
//是否有層次線
lines: true,
//菜單打開與關(guān)閉是否有動畫效果
animate: true,
//菜單點擊事件
onClick: function(node){
if(node.attributes && node.attributes.url){
//打開內(nèi)容區(qū)的tab,代碼在其后
addTab({
url: "${ctx }/" + node.attributes.url,
title: node.text
});
}
}
});
/*
* 初始化內(nèi)容區(qū)的tabs
*/
$("#home-tabs").tabs({
fit : true,
//tab頁是否有邊框
border : false
});})
</script>
<script>
/*
* 在內(nèi)容區(qū)添加一個tab
*/
function addTab(params){
var t = $("#home-tabs");
var url = params.url;
var opts = {
title: params.title,
closable: true,
href: url,
fit: true,
border: false
};
//如果被選中的節(jié)點對應(yīng)的tab已經(jīng)存在,則選中該tab并刷新內(nèi)容
//否則打開一個新的tab
if(t.tabs("exists", opts.title)){
var tab = t.tabs("select", opts.title).tabs("getSelected");
t.tabs("update", {
tab: tab,
options: opts
});
}else{
t.tabs("add", opts);
}
}
</script>
4.easyui-tree組件所需的json格式
easyui使用的傳輸格式為json,它對json內(nèi)容的格式有比較嚴格的限制,所以請注意查看api
[{
"text":"區(qū)域管理",
"attributes":{
"url":"pages/consume/area/areaList.jsp"
}
},{
"text":"預(yù)約信息管理",
"children":[{
"text":"商戶預(yù)約信息查詢",
"attributes":{
"url":"/pages/consume/reservation/merchantReservation/merchantReservationList.jsp"
}
}]
},{
"text":"準入申請管理",
"children":[{
"text":"商戶準入申請",
"state":"closed",
"children":[{
"text":"商戶待處理申請",
"attributes":{
"url":"waterAply.do?method=toList&channelType=1&handleFlag=aply_wait"
}
},{
"text":"商戶審批中申請",
"attributes":{
"url":"waterAply.do?method=toList&channelType=1&handleFlag=aply_current"
}
},{
"text":"商戶審批通過申請",
"attributes":{
"url":"waterAply.do?method=toList&channelType=1&handleFlag=aply_pass"
}
},{
"text":"商戶被拒絕申請",
"attributes":{
"url":"waterAply.do?method=toList&channelType=1&handleFlag=aply_refuse"
}
}]
}]
},{
"text":"準入審批管理",
"children":[{
"text":"商戶審批管理",
"state":"closed",
"children":[{
"text":"當前任務(wù)",
"children":[{
"text":"商戶當前初審任務(wù)",
"attributes":{
"url":"pages/consume/approval/merchantApproval/merchantApprovalTrial.jsp"
}
},{
"text":"商戶當前復審任務(wù)",
"attributes":{
"url":"pages/consume/approval/merchantApproval/merchantApprovalRetrial.jsp"
}
}]
},{
"text":"商戶已完成任務(wù)",
"attributes":{
"url":"pages/consume/approval/merchantApproval/merchantApprovalDone.jsp"
}
},{
"text":"商戶不通過任務(wù)",
"attributes":{
"url":"pages/consume/approval/merchantApproval/merchantApprovalRefuse.jsp"
}
}]
}]
}]
就這樣,我們使用easyui完成了簡單的左右布局。
以上所述是小編給大家分享的jQuery Easyui實現(xiàn)上左右布局的相關(guān)內(nèi)容,希望對大家有所幫助。
- jQuery Easyui使用(一)之可折疊面板的布局手風琴菜單
- JQuery EasyUI Layout 在from布局自適應(yīng)窗口大小的實現(xiàn)方法
- jQuery EasyUi實戰(zhàn)教程之布局篇
- jQuery EasyUI 布局之動態(tài)添加tabs標簽頁
- JQueryEasyUI Layout布局框架的使用
- Jquery組件easyUi實現(xiàn)手風琴(折疊面板)示例
- Jquery組件easyUi實現(xiàn)選項卡切換示例
- Jquery組件easyUi實現(xiàn)表單驗證示例
- jQuery EasyUI API 中文文檔 - DataGrid數(shù)據(jù)表格
- jQuery組件easyui基本布局實現(xiàn)代碼
相關(guān)文章
jQuery刪除節(jié)點的三個方法即remove()detach()和empty()
jQuery提供了三種刪除節(jié)點的方法,即remove(),detach()和empty(),下面為大家詳細介紹下jQuery刪除節(jié)點三個方法的具體使用2013-12-12
jquery實現(xiàn)帶漸變淡入淡出并向右依次展開的多級菜單效果實例
這篇文章主要介紹了jquery實現(xiàn)帶漸變淡入淡出并向右依次展開的多級菜單效果,涉及jquery鼠標事件及頁面元素動態(tài)樣式設(shè)置的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08
jquery xMarquee實現(xiàn)文字水平無縫滾動效果
這篇文章主要介紹了jquery xMarquee實現(xiàn)文字水平無縫滾動效果,需要的朋友可以參考下2014-04-04

