jQuery 计算jquery中现有选项卡的数量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1175380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:50:09  来源:igfitidea点击:

count the number of existing tabs in jquery?

jquerytabs

提问by Robert Harvey

I'm using a dynamic jQuery tab widget to add/remove tabs generated programmatically.

我正在使用动态 jQuery 选项卡小部件来添加/删除以编程方式生成的选项卡。

How do I check through jQuery and count how many existing tabs are present in the widget?

如何检查 jQuery 并计算小部件中存在多少个现有选项卡?

I'm using this code, but it doesn't work:

我正在使用此代码,但它不起作用:

$('#container-1 > ul').tabs('add', tabName, name);

var newTab;

if ($('#container-1 > li').size() < 0) {
    newTab = $(tabName).css('display', 'block')
} else {
    newTab = $(tabName).css('display', 'none');
}

newTab.html('<iframe src="ViewPatient.aspx?pname=' + name 
       + '" width="100%" frameborder="0" scrolling="no" height="300"></iframe>');

回答by Wolfgang

Just use the below code

只需使用下面的代码

$('#selector >ul >li').size();

where "#selector" is the selector you have used to create the tabs.

其中“#selector”是您用于创建选项卡的选择器。

UPDATE

更新

size()function doesn't exist any more, now the solution is:

size()函数不再存在,现在解决方案是:

$('#selector >ul >li').length;

回答by Robert Harvey

var tabCount = $(tabContainer).tabs("length");