update okTab
parent
93ebbd1a56
commit
726259ac49
|
|
@ -46,17 +46,17 @@ layui.use(["element", "layer"], function () {
|
|||
* @param path 路径
|
||||
* @param tabId tabId必须唯一
|
||||
*/
|
||||
window.tabAdd = function (title, path, tabId) {
|
||||
if (self == top) {
|
||||
// console.log("不在iframe中")
|
||||
tabAdd1(title, path, tabId)
|
||||
} else {
|
||||
// console.log("在iframe中")
|
||||
tabAdd2(title, path, tabId)
|
||||
}
|
||||
}
|
||||
// window.tabAdd = function (title, path, tabId) {
|
||||
// if (self == top) {
|
||||
// // console.log("不在iframe中")
|
||||
// tabAdd1(title, path, tabId)
|
||||
// } else {
|
||||
// // console.log("在iframe中")
|
||||
// tabAdd2(title, path, tabId)
|
||||
// }
|
||||
// }
|
||||
|
||||
function tabAdd1(title, path, tabId) {
|
||||
function tabAdd(title, path, tabId) {
|
||||
// 参数校验
|
||||
parameterCheck(title, path, tabId);
|
||||
// 去重复选项卡
|
||||
|
|
@ -79,29 +79,29 @@ layui.use(["element", "layer"], function () {
|
|||
element.tabChange("ok-tab", tabId);
|
||||
}
|
||||
|
||||
function tabAdd2(title, path, tabId) {
|
||||
// 参数校验
|
||||
parameterCheck(title, path, tabId);
|
||||
// 去重复选项卡
|
||||
var parentOkFrame = $(".ok-frame", parent.document);
|
||||
for (var i = 0; i < parentOkFrame.length; i++) {
|
||||
var _tabId = parentOkFrame.eq(i).attr("tab-id");
|
||||
if (_tabId == tabId) {
|
||||
console.warn("tabId=" + tabId + "有重复元素,请检查!")
|
||||
parent.layui.element.tabChange("ok-tab", tabId);
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 添加选项卡
|
||||
parent.layui.element.tabAdd("ok-tab", {
|
||||
title: title,
|
||||
content: "<iframe src='" + path + "' tab-id='" + tabId + "' class='ok-frame' frameborder='0' scrolling='yes' width='100%' height='100%'></iframe>",
|
||||
id: tabId
|
||||
});
|
||||
// 切换选项卡
|
||||
parent.layui.element.tabChange("ok-tab", tabId);
|
||||
}
|
||||
// function tabAdd2(title, path, tabId) {
|
||||
// // 参数校验
|
||||
// parameterCheck(title, path, tabId);
|
||||
// // 去重复选项卡
|
||||
// var parentOkFrame = $(".ok-frame", parent.document);
|
||||
// for (var i = 0; i < parentOkFrame.length; i++) {
|
||||
// var _tabId = parentOkFrame.eq(i).attr("tab-id");
|
||||
// if (_tabId == tabId) {
|
||||
// console.warn("tabId=" + tabId + "有重复元素,请检查!")
|
||||
// parent.layui.element.tabChange("ok-tab", tabId);
|
||||
// event.stopPropagation();
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// // 添加选项卡
|
||||
// parent.layui.element.tabAdd("ok-tab", {
|
||||
// title: title,
|
||||
// content: "<iframe src='" + path + "' tab-id='" + tabId + "' class='ok-frame' frameborder='0' scrolling='yes' width='100%' height='100%'></iframe>",
|
||||
// id: tabId
|
||||
// });
|
||||
// // 切换选项卡
|
||||
// parent.layui.element.tabChange("ok-tab", tabId);
|
||||
// }
|
||||
|
||||
function parameterCheck(title, path, tabId) {
|
||||
if (title == undefined || title == "") {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
layui.define(["element", "layer"], function (exports) {
|
||||
var element = layui.element;
|
||||
var element = parent.layui.element;
|
||||
var layer = layui.layer;
|
||||
var $ = layui.jquery;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@
|
|||
okTab.tabAdd("ok-tool", "http://www.xlbweb.cn", "11-1")
|
||||
</pre>
|
||||
|
||||
<button class="layui-btn" id="addTab">打开一个新的Tab</button>
|
||||
<button class="layui-btn" id="addTab1">打开一个新的Tab1</button>
|
||||
<button class="layui-btn" id="addTab2">打开一个新的Tab2</button>
|
||||
</div>
|
||||
<!--js逻辑-->
|
||||
<script src="../../lib/layui/layui.js"></script>
|
||||
|
|
@ -80,8 +81,12 @@ okTab.tabAdd("ok-tool", "http://www.xlbweb.cn", "11-1")
|
|||
|
||||
layui.code({about: false});
|
||||
|
||||
$("#addTab").click(function () {
|
||||
okTab.add("ok-tool", "http://tool.xlbweb.cn", "11-1");
|
||||
$("#addTab1").click(function () {
|
||||
okTab.add("ok-tool", "pages/use/use-okLayer.html", "11-1");
|
||||
});
|
||||
|
||||
$("#addTab2").click(function () {
|
||||
okTab.add("ok-tool", "http://tool.xlbweb.cn", "11-2");
|
||||
});
|
||||
})
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue