Skip to content

页签

页签控件用于在同一个区域内切换显示多个内容页。

属性

autoheight

  • 说明:自动调高
  • 类型boolean
  • 默认值true

可选值

说明
true开启
false关闭

示例

json
"autoheight":true

sg-list

  • 说明:页签列表配置
  • 类型Array

sg-list 参数说明

参数名类型必填说明
keystring页签文字
codestring页签编码
pageidstring页面 id,支持 Get 传参(与 url 二选一)
urlstring页签 iframe 页面(与 pageid 二选一)
scrollingboolean是否支持滚动
activeboolean页签默认活动状态

示例

json
"sg-list":[
    {
        "key":"这是页签A",
        "code":"tab_01",
        "pageid":"608&aaa=123",
        "scrolling":false,
        "active":true
    }
]

sg-loaddata

  • 说明:自动渲染页签
  • 类型boolean
  • 默认值true

可选值

说明
true开启
false关闭

示例

json
"sg-loaddata":true

方法

renderTabBox

渲染页签。

语法

js
renderTabBox(id, list, params)

参数

参数名类型必填说明
idstring页签 id
listArray页签列表
paramsObject页签参数

list / params 参数说明

参数名类型必填说明
pageidstring页面 id,支持 Get 传参(与 url 二选一)
urlstring页签 iframe 页面(与 pageid 二选一)
keystring页签文字
codestring页签编码
scrollingboolean是否支持滚动
activeboolean页签默认活动状态

示例

js
// 渲染包含多个页签的页签容器
var tabList = [
    {
        pageid: "user_info_page",
        key: "用户信息",
        code: "user_info",
        scrolling: false,
        active: true
    },
    {
        pageid: "order_history_page",
        key: "订单历史",
        code: "order_history",
        scrolling: true,
        active: false
    }
];

var tabParams = {
    style: "height:500px"
};

renderTabBox("user_tab_container", tabList, tabParams);

addOneTab

添加页签。

语法

js
addOneTab(id, params)

参数

参数名类型必填说明
idstring页签 id
paramsObject页签参数

params 参数说明

参数名类型必填说明
pageidstring页面 id
keystring页面名称
codestring页面编码
scrollingboolean是否显示滚动条
activeboolean活动状态

示例

js
// 动态添加一个新的页签
var newTabParams = {
    pageid: "product_detail&productId=12345",
    key: "产品详情",
    code: "product_12345",
    scrolling: false,
    active: true
};

addOneTab("main_tab_container", newTabParams);

displayOneTab

页签显示操作。

语法

js
displayOneTab(id, code, index, mode)

参数

参数名类型必填说明
idstring页签容器 id
codestring页签 code(code 和 index 二选一)
indexnumber页签 index(code 和 index 二选一)
modestring操作模式:remove(移除)、show(显示)、hide(隐藏)

示例

js
// 隐藏指定页签
displayOneTab("main_tab_container", "user_info", null, "hide");

// 显示指定页签
displayOneTab("main_tab_container", "user_info", null, "show");

// 移除指定页签(无法恢复)
displayOneTab("main_tab_container", "temp_tab", null, "remove");

// 使用 index 参数隐藏页签
displayOneTab("main_tab_container", null, 2, "hide");

findTabBoxObj

获取页签里面的对象。

语法

js
findTabBoxObj(id, selector, code, index)

参数

参数名类型必填说明
idstring页签容器 id
selectorstringjQuery 选择器
codestring页签 code(code 和 index 二选一)
indexnumber页签 index(code 和 index 二选一)

示例

js
// 获取指定页签内的表单控件
var usernameInput = findTabBoxObj("user_tab_container", "#username", "user_info", null);
usernameInput.val("张三");

// 获取指定页签内的按钮并绑定事件
var saveButton = findTabBoxObj("user_tab_container", ".save-btn", "user_info", null);
saveButton.click(function() {
    console.log("保存用户信息");
});

// 使用 index 参数获取页签内的元素
var emailInput = findTabBoxObj("user_tab_container", "#email", null, 0);
emailInput.val("user@example.com");

getTabBoxPage

获取内嵌页面。

语法

js
getTabBoxPage(id, code, index)

参数

参数名类型必填说明
idstring页签容器 id
codestring页签 code(code 和 index 二选一)
indexnumber页签 index(code 和 index 二选一)

示例

js
// 获取指定页签的内嵌页面对象并调用其方法
var userTabPage = getTabBoxPage("main_tab_container", "user_info", null);
if (userTabPage && typeof userTabPage.refreshData === 'function') {
    userTabPage.refreshData();
}

// 获取页签页面并访问其属性
var orderTabPage = getTabBoxPage("main_tab_container", "order_history", null);
if (orderTabPage) {
    console.log("当前页签状态:", orderTabPage.pageStatus);
}

// 使用 index 参数获取页签页面
var thirdTabPage = getTabBoxPage("main_tab_container", null, 2);
if (thirdTabPage && typeof thirdTabPage.loadData === 'function') {
    thirdTabPage.loadData();
}

pageBoxAutoHeight

自动调整 iframe 高度(子页面调用)。

语法

js
pageBoxAutoHeight()

示例

js
// 在页签内的子页面中调用,自动调整 iframe 高度以适应内容
$(document).ready(function() {
    // 页面内容加载完成后调整高度
    pageBoxAutoHeight();

    // 当页面内容发生变化时再次调整高度
    $("#expand-content").click(function() {
        // 展开更多内容...
        pageBoxAutoHeight();
    });
});

基于 MIT 许可发布