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