gpt4 book ai didi

javascript - 在 dojo 选项卡容器中选择选项卡时如何调用函数?

转载 作者:行者123 更新时间:2023-11-30 13:31:43 24 4
gpt4 key购买 nike

我有一个带有选项卡的选项卡容器,根据选择的选项卡,我想要运行一个函数。我已经在 J​​ava Script 中创建了函数,它将隐藏或显示窗口。该功能工作正常。我如何告诉选项卡运行此功能?在下面的代码中,我在选项卡的“内容”中显示了一个名为“隐藏”的函数。我还有一个名为“showdiv”的函数。我想从内容中删除它,并在选择选项卡时让它自动运行。有什么建议么?我根本不希望它影响选项卡的内容。
谢谢!

            <div dojoType="dijit.layout.ContentPane" title="Setup">
<a href="javascript:hidediv()">Hide div</a>
</div>

最佳答案

这在 reference guide 中有详细描述.

基本上,如果您的 TabContainer 的 ID 为“myTabs”,您可以:

dojo.subscribe("myTabs-selectChild", function(selected){
// Do whatever you need here, hidediv() etc..
console.log(selected.title);
});

编辑:如果您只想为特定选项卡触发某些内容,您可以检查函数内的标题:

dojo.subscribe("myTabs-selectChild", function(selected){
if(selected.title == "Setup")
{
hidediv();
}
});

也许更优雅的方法是使用 ContentPane 的 onShow 事件,例如:

<div dojoType="dijit.layout.ContentPane" title="Setup"
onShow="hidediv">
<!-- Content -->
</div>

关于javascript - 在 dojo 选项卡容器中选择选项卡时如何调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6536808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com