jQuery Easyui實(shí)現(xiàn)左右布局
EasyUI 簡介
easyui是一種基于jQuery的用戶界面插件集合。
easyui為創(chuàng)建現(xiàn)代化,互動(dòng),JavaScript應(yīng)用程序,提供必要的功能。
使用easyui你不需要寫很多代碼,你只需要通過編寫一些簡單HTML標(biāo)記,就可以定義用戶界面。
easyui是個(gè)完美支持HTML5網(wǎng)頁的完整框架。
easyui節(jié)省您網(wǎng)頁開發(fā)的時(shí)間和規(guī)模。
easyui很簡單但功能強(qiáng)大的。
在后臺管理系統(tǒng)開發(fā)的過程中,上左右的布局是最常見的頁面布局方式,現(xiàn)在我們來看看使用easyui這個(gè)jquery前端框架如何快速搭建一個(gè)可用的頁面框架。
1.在頁面中引入easyui所需的文件
<%-- 加載easyui的樣式文件,bootstrap風(fēng)格 --%> <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"> <!-- 頁面北部,頁面標(biāo)題 --> <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>
這里需要注意一點(diǎn):easyui在使用layout布局的時(shí)候,north、south需要指定高度,west、east需要指定寬度,而center會(huì)自動(dòng)適應(yīng)高和寬。
3.使用js初始化easyui組件
我個(gè)人比較推薦使用js代碼去初始化easyui組件,而不使用easyui標(biāo)簽中的data-options屬性去初始化。因?yàn)閷τ诤笈_開發(fā)人員來說,寫js代碼可能比寫html標(biāo)簽更加熟悉,而且這樣使得html代碼更加簡潔。
<script> $(function(){ /* * 初始化layout */ $("#home-layout").layout({ //使layout自適應(yīng)容器 fit: true }); /* * 獲取左側(cè)菜單樹,并為其節(jié)點(diǎn)指定單擊事件 */ $("#home-west-tree").tree({ //加載菜單的數(shù)據(jù),必需 url: "${ctx }/pages/home-west-tree.json", method: "get", //是否有層次線 lines: true, //菜單打開與關(guān)閉是否有動(dòng)畫效果 animate: true, //菜單點(diǎn)擊事件 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ū)添加一個(gè)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é)點(diǎn)對應(yīng)的tab已經(jīng)存在,則選中該tab并刷新內(nèi)容 //否則打開一個(gè)新的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)容的格式有比較嚴(yán)格的限制,所以請注意查看api
[{ "text":"區(qū)域管理", "attributes":{ "url":"pages/consume/area/areaList.jsp" } },{ "text":"預(yù)約信息管理", "children":[{ "text":"商戶預(yù)約信息查詢", "attributes":{ "url":"/pages/consume/reservation/merchantReservation/merchantReservationList.jsp" } }] },{ "text":"準(zhǔn)入申請管理", "children":[{ "text":"商戶準(zhǔn)入申請", "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":"準(zhǔn)入審批管理", "children":[{ "text":"商戶審批管理", "state":"closed", "children":[{ "text":"當(dāng)前任務(wù)", "children":[{ "text":"商戶當(dāng)前初審任務(wù)", "attributes":{ "url":"pages/consume/approval/merchantApproval/merchantApprovalTrial.jsp" } },{ "text":"商戶當(dāng)前復(fù)審任務(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實(shí)現(xiàn)上左右布局的相關(guān)內(nèi)容,希望對大家有所幫助。
- jQuery Easyui使用(一)之可折疊面板的布局手風(fēng)琴菜單
- JQuery EasyUI Layout 在from布局自適應(yīng)窗口大小的實(shí)現(xiàn)方法
- jQuery EasyUi實(shí)戰(zhàn)教程之布局篇
- jQuery EasyUI 布局之動(dòng)態(tài)添加tabs標(biāo)簽頁
- JQueryEasyUI Layout布局框架的使用
- Jquery組件easyUi實(shí)現(xiàn)手風(fēng)琴(折疊面板)示例
- Jquery組件easyUi實(shí)現(xiàn)選項(xiàng)卡切換示例
- Jquery組件easyUi實(shí)現(xiàn)表單驗(yàn)證示例
- jQuery EasyUI API 中文文檔 - DataGrid數(shù)據(jù)表格
- jQuery組件easyui基本布局實(shí)現(xiàn)代碼
相關(guān)文章
jQuery 選擇方法及$(this)用法實(shí)例分析
這篇文章主要介紹了jQuery 選擇方法及$(this)用法,結(jié)合實(shí)例形式分析了jQuery 選擇方法及$(this)相關(guān)使用技巧與注意事項(xiàng),需要的朋友可以參考下2020-05-05BootStrap 標(biāo)題設(shè)置跨行無效的解決方法
這篇文章主要介紹了BootStrap 標(biāo)題設(shè)置跨行無效的解決方法,需要的朋友可以參考下2017-10-10jQuery學(xué)習(xí)之prop和attr的區(qū)別示例介紹
prop和attr的區(qū)別你知道嗎?在本文有些不錯(cuò)的示例對兩者詳細(xì)介紹,感興趣的朋友不要錯(cuò)過2013-11-11jQuery刪除節(jié)點(diǎn)的三個(gè)方法即remove()detach()和empty()
jQuery提供了三種刪除節(jié)點(diǎn)的方法,即remove(),detach()和empty(),下面為大家詳細(xì)介紹下jQuery刪除節(jié)點(diǎn)三個(gè)方法的具體使用2013-12-12jquery實(shí)現(xiàn)帶漸變淡入淡出并向右依次展開的多級菜單效果實(shí)例
這篇文章主要介紹了jquery實(shí)現(xiàn)帶漸變淡入淡出并向右依次展開的多級菜單效果,涉及jquery鼠標(biāo)事件及頁面元素動(dòng)態(tài)樣式設(shè)置的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08jquery xMarquee實(shí)現(xiàn)文字水平無縫滾動(dòng)效果
這篇文章主要介紹了jquery xMarquee實(shí)現(xiàn)文字水平無縫滾動(dòng)效果,需要的朋友可以參考下2014-04-04商城常用滾動(dòng)的焦點(diǎn)圖效果代碼簡單實(shí)用
此效果在網(wǎng)上使用的頻率比較多一點(diǎn)但大多是插件,要么JS寫的太過于復(fù)雜童鞋們看起來有一定的難度,這個(gè)相對來說比較簡單一點(diǎn),感興趣的可以參考下哈2013-03-03