標籤:easyui ajax layout tabs href
<!DOCTYPE HTML><html><head><meta http-equiv="content-type" content="text/html" /><meta name="author" content="blog.anchen8.net" /> <script type="text/javascript" src="__PUBLIC__/jquery-easyui-1.4.1/jquery.min.js"></script><script type="text/javascript" src="__PUBLIC__/jquery-easyui-1.4.1/jquery.easyui.min.js"></script><link rel="stylesheet" type="text/css" href="__PUBLIC__/jquery-easyui-1.4.1/themes/default/easyui.css"> <link rel="stylesheet" type="text/css" href="__PUBLIC__/jquery-easyui-1.4.1/themes/icon.css"> <title>easyui測試</title> <style> .ico{width:300px;height:200px;float:left;} .menu{width:150px;height:50px;margin-top:5px;} ul{text-align:left;} li{text-align:left;} </style> <script> var url="<{:U('User/getUserList')}>"; $(function(){ //tabs綁定右鍵事件 $('#tabs').tabs({ //添加預設tab onContextMenu:function(e,title){ e.preventDefault();//取消對象e的預設事件 $('#rightmenu').menu('show',{ left: e.pageX, top: e.pageY }); $('#tabs').tabs('select', title); }, }); //tree綁定單擊事件 $('#menu_tree').tree({ onClick:function(node){ //添加節點到panel中 //alert(JSON.stringify(node)); var title=node.text; if($('#tabs').tabs('exists',title) || node.children){ $('#tabs').tabs('select',title); }else{ $('#tabs').tabs('add',{ title:title, closable:true, //content: '<iframe src="' + url + '" frameborder=0 height=100% width=100% scrolling=no></iframe>',//frame載入所需要頁面。href:只是載入頁面,且不能跨域 <strong> </strong><span style="color:#000099;"><strong>href:'www.baidu.com'</strong>,</span> msg :"正在載入資料,請稍候...", tabWidth:100 }); } } }); // 全部關閉 $('#closeall').click(function() { var taball = $('#tabs').tabs('tabs'); var title = []; var j = 0; for (var i = 0 in taball) { <span style="color:#CC0000;">console.dir(taball[i].panel('options'));</span> if (taball[i].panel('options').closable) { title[j] = taball[i].panel('options').title; j++; title.length = j; } } for (var v = 0 in title) { $('#tabs').tabs('close', title[v]); } }); // 關閉當前 $('#closethis').click(function() { var currTab = $('#tabs').tabs('getSelected'); if (currTab.panel('options').closable) { $('#tabs').tabs('close', currTab.panel('options').title); } }); // 關閉除當前之外的TAB $('#closeother').click(function() { var taball = $('#tabs').tabs('tabs'); var currTab = $('#tabs').tabs('getSelected'); var currTitle = currTab.panel('options').title; var title = []; var j = 0; for (var i = 0 in taball) { if (taball[i].panel('options').title != currTitle) { if (taball[i].panel('options').closable) { title[j] = taball[i].panel('options').title; j++; title.length = j; } } } if (j == 0) { showMsg('沒有可關閉的選項卡了!'); } else { for (var v = 0 in title) { $('#tabs').tabs('close', title[v]); } } return false; }); // 關閉當前右側的TAB $('#closeright').click(function() { var taball = $('#tabs').tabs('tabs'); var currTab = $('#tabs').tabs('getSelected'); var currTitle = currTab.panel('options').title; var title = []; var j = 0; var st = false; for (var i = 0 in taball) { if (currTitle == taball[i].panel('options').title) { st = true; } if (st) { if (taball[i].panel('options').title != currTitle) { if (taball[i].panel('options').closable) { title[j] = taball[i].panel('options').title; j++; title.length = j; } } } } if (j == 0) { showMsg('右側沒有可關閉的選項卡了!'); } else { for (var v = 0 in title) { $('#tabs').tabs('close', title[v]); } } return false; }); // 關閉當前左側的TAB $('#closeleft').click(function() { var taball = $('#tabs').tabs('tabs'); var currTab = $('#tabs').tabs('getSelected'); var currTitle = currTab.panel('options').title; var title = []; var j = 0; var st = true; for (var i = 0 in taball) { if (currTitle == taball[i].panel('options').title) { st = false; } if (st) { if (taball[i].panel('options').closable) { title[j] = taball[i].panel('options').title; j++; title.length = j; } } } if (j == 0) { showMsg('左側側沒有可關閉的選項卡了!'); } else { for (var v = 0 in title) { $('#tabs').tabs('close', title[v]); } } }); // 退出 $("#mmexit").click(function() { $('#tabmenus').menu('hide'); }); }); </script></head><body class="easyui-layout" id="body"> <div data-options="region:'north',split:true" style="height:100px;"> <div class="ico">按鈕一</div> <div class="ico">按鈕二</div> <div class="ico">按鈕三</div> <div class="ico">按鈕四</div> </div> <div data-options="region:'west',split:true" style="width:150px;" > <!-- <div style="width:150px;height:50px;margin-top:5px;border:1px solid gray">系統設定</div> <div style="width:150px;height:50px;margin-top:5px;border:1px solid gray">會員管理</div> <div style="width:150px;height:50px;margin-top:5px;border:1px solid gray">每日上市</div> --> <div class="easyui-accordion"> <div title="導覽功能表" data-options="iconCls:'icon-nav',collapsible:false" style="overflow:auto;padding:10px;"> </div> <div title="便利店設定" data-options="iconCls:'icon-set',selected:true" style="padding:10px;"> <ul class="easyui-tree" id="menu_tree"> <li>大廚特製</li> <li>小吃東西</li> <li> <span>其他東西</span> <ul> <li>即食麵</li> <li>挂面</li> <li>面</li> </ul> </li> </ul> </div> <div title="便利店設定" style="padding:10px;"> </div> </div> </div> <div data-options="region:'center',split:true" id="tab_parent"> <div class="easyui-tabs" id="tabs" style="height:800px;"> <div title="系統設定" data-options="closable:false" style="overflow:auto;padding:20px;display:none;"> 系統設定 </div> </div> </div> <div id="rightmenu" class="easyui-menu" style=""> <div data-options="iconCls:'icon-cancel'" id="closethis"> 關閉 </div> <div id="closeall"> 關閉全部 </div> <div id="closeother"> 關閉其他 </div> <div class="menu-sep"></div> <div id="closeright"> 關閉右側標籤頁 </div> <div id="closeleft"> 關閉左側標籤頁 </div> </div></body></html>
tabs載入頁面分為兩種方式
href方式載入資料的特點:
- 被載入的頁面只有body元素內部的內容才會被載入,也就是jQuery的ajax請求的只是html片段。
- 載入遠程url時有遮罩效果,也就是“等待中……”效果,使用者體驗較好。
- 當載入的頁面配置較為複雜,或者有較多的js指令碼需要啟動並執行時候,編碼往往就需要謹慎了,容易出問題,後面會詳細談
content方式載入資料的特點:
- 比較靈活,你可以在指令碼裡面拼字html代碼,然後賦值給tab的content屬性,不過這種寫法會使得代碼易讀性變差。
- 可以把iframe賦給content,把一個iframe嵌入也就沒有什麼不能完成的了。
- 使用iframe會造成用戶端js重複載入,浪費資源,比如說你首頁面要引用easyui的庫,你的iframe也要引用,浪費就產生了。
在代碼藍色字型(href:‘www.baidu.com‘,)中,easyui無法載入百度網站的內容,換其他網站嘗試也不可以。究其原因在於,瀏覽器在進行ajex跳轉時,為了保證伺服器安全和資料安全,瀏覽器會禁止跨域ajex的請求。打個比方:某個網站的某張頁面被你寫入了一些js ,這些js有些ajax操作
如果某個使用者訪問了這張頁面,你的js就可以獲得使用者的某些資訊(cookie,本地檔案等)然後通過ajax發送回你的伺服器。 這樣你就可以獲得任意你想獲得的資料了。ajex的存在本身就是簡化請求和不斷重新整理,禁用跨域可以保證ajex使用者的安全。因此easyui在href中,也會禁止ajex的跨域請求。但是並不是說你想載入其他網域名稱的內容不能實現。可以採用content載入方式。將藍色文字替換為:
content: ‘<iframe src="‘ + url + ‘" frameborder=0 height=100% width=100% scrolling=no></iframe>‘其中url替換成任意的網址即可。
問題:
1.tabs是panel的子類,tabs依賴於panel,那為什麼64行部分不能改為:希望大家指教下
console.dir(taball[i].tabs('options'));
解決easyui tabs中href無法跨域跳轉