博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tabs扩展:按照标签页ID进行检索
阅读量:7040 次
发布时间:2019-06-28

本文共 1628 字,大约阅读时间需要 5 分钟。

hot3.png

扩展方式实现

本文只举两个扩展方式的例子,实现select和exists两个接口按照ID检索功能,其它类似接口,可以仿照着写:

/** * @author {CaoGuangHui} */$.extend($.fn.tabs.methods, {    getTabById: function(jq,id) {        var tabs = $.data(jq[0], 'tabs').tabs;        for(var i=0; i
div.tabs-header>div.tabs-wrap');            var left = tab.position().left;            var right = left + tab.outerWidth();            if (left < 0 || right > wrap.width()){                var deltaX = left - (wrap.width()-tab.width()) / 2;                $(this).tabs('scrollBy', deltaX);            } else {                $(this).tabs('scrollBy', 0);            }            $(this).tabs('resize');            opts.onSelect.call(this, title, $(this).tabs('getTabIndex',panel));        });    },    existsById:function(jq,id){        return $(jq[0]).tabs('getTabById',id) != null;    }});

使用方法:

var tab = $("tabs").tabs("selectById","tabId");var isExist = $("tabs").tabs("existsById","tabId");

这段代码扩展了三个接口,但是只有selectById和existById才会直接用到,使用这两个方法的时候传入ID参数即可。

演示实例:

引入各大需要的js

    

编写html

 
selectTab

编写js:

var index = 0; function addPanel(){ index++; $('#tt').tabs('add',{                id: 'id'+index, title: 'Tab'+index, content: '
Content'+index+'', closable: true }); }

编写判断代码:

function selectTab(){            var isExist = $("#tt").tabs("existsById","id2");            if (isExist) {            	 var tab = $("#tt").tabs("selectById","id2");            	}else{            		addPanel();            	}        }

转载于:https://my.oschina.net/ihanfeng/blog/283028

你可能感兴趣的文章
python开发项目:学生选课系统
查看>>
起一个洋气一点的名字
查看>>
.net向android的转型(2)
查看>>
windows service 调试
查看>>
http缓存机制
查看>>
elasticsearch系列(二) esrally压测
查看>>
python基础===中文手册,可查询各个模块
查看>>
protobuf自解释message
查看>>
No Delegate set : lost message:libpng error: Not a PNG file
查看>>
win7 APPCRASH(解决方法)(转)
查看>>
EL表达式的语法介绍及九大隐含对象
查看>>
DoTween(HOTween V2) 教程
查看>>
Unity键值(KeyCode)
查看>>
ffmpeg-20160515-git-bin
查看>>
如何找到字符中出现最多的字符
查看>>
淘宝卖家过劳死VS富士康跳楼死
查看>>
Process和Thread在指定CPU运行
查看>>
PowerShell连接中国Azure
查看>>
python中的验证码识别库PyTesser
查看>>
[kuangbin带你飞]专题一 简单搜索 - C - Catch That Cow
查看>>