简体   繁体   English

如何在JavaScript中选择标签并设置标签面板的内容

[英]How do I select a tab and set content of the tabpanel in JavaScript

I'm stuck at this: I've created tabs and corresponding tabpanels. 我被困在这里:我已经创建了选项卡和相应的选项卡面板。 By default, I've hidden the tabs. 默认情况下,我隐藏了选项卡。 To make a tab visible, I use this JavaScript line: 为了使标签可见,我使用了以下JavaScript行:

document.getElementById("tab-id").setAttribute("selected", true);

However, the content of the corresponding tabpanel does not update as I expected. 但是,相应的tabpanel的内容不会按我预期的那样更新。 I've tried using this: 我试过使用这个:

document.getElementById("tabbox-id").selectedPanel = "tabpanel-id";

But nothing is happening; 但是什么也没有发生。 the content of the tabpanel is not updated. 该内容tabpanel不会被更新。

Any assistance will be highly appreciated. 任何帮助将不胜感激。

The selected attribute is set internally, it is merely an indicator that selection changed - changing it won't actually change selection. selected属性是在内部设置的,它仅指示选择已更改-更改它实际上不会更改选择。 What you most likely want to do is this: 您最可能想做的是:

var tabpanel = document.getElementById("tabpanel-id");
document.getElementById("tabbox-id").selectedPanel = tabpanel;

Note that selectedPanel is the panel and not its ID. 请注意, selectedPanel是面板,而不是其ID。 Alternatively you could also use selectedIndex : 或者,您也可以使用selectedIndex

document.getElementById("tabbox-id").selectedIndex = 1;

Documentation 文献资料

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在标签面板onclick中创建标签? - how do i create a tab in a tabpanel onclick? 如何在不更改ExtJS中的卡片的情况下在选项卡面板中选择选项卡? - How can I choose a tab in a tabpanel without changing the card in ExtJS? 如何立即选择并显示隐藏的jquery ui选项卡的内容,使其在按钮单击时可见 - How do I immediately select and show the content of a hidden jquery ui tab that is made visible on a button click 如何通过jQuery选择活动选项卡选择选项卡内容在ul元素之外的位置? - How to set active tab via jQuery select where tab content is outside of ul element? 如何更改内容,而不更改Spry选项卡式面板的选项卡? - How do I change the content but not the tab with Spry Tabbed Panels? 如何在当前选项卡中停止执行内容脚本? - How do I stop content script execution in the current tab? 如何在jQuery选项卡中的子页面内容中使用.on()? - How do I use .on() for subpage content within a jQuery tab? 如何将按钮链接到另一页上具有div内容的选项卡? - How do I link a button to a tab with div content on another page? 如何链接到选项卡式部分并打开选项卡内容? - How do I link to tabbed section and open the tab content? 在ExtJS 4的选项卡面板中,如何创建父选项卡包括2个子选项卡 - In the tabpanel of ExtJS 4, how to create parent tab includes 2 child tab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM