如何“获取”dijit.layout.tabcontainer 中“单击”选项卡的 ID?

2024-01-08

我一直无法为此找到明确定义的解决方案。大多数都是不完整的片段。

这是一个简单的示例。请参阅 doSomething() 注释:

<head>
    <style type="text/css">
        body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
    </style>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css"/>
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"
    djConfig="parseOnLoad: true">
    </script>
    <script type="text/javascript">
        dojo.require("dijit.layout.TabContainer");
        dojo.require("dijit.layout.ContentPane");

    function doSomething() {
        //Put code in here that identifies the clicked tab and displays it's id in the below alert
        alert("Hello World!");
    }   

    </script>

</head>

<body class=" claro ">
    <div id="mainTab" dojoType="dijit.layout.TabContainer" style="width: 400px; height: 100px;" onClick="doSomething();">
        <div id="tab1" dojoType="dijit.layout.ContentPane" title="My first tab" selected="true">
            Lorem ipsum and all around...
        </div>
        <div id="tab2" dojoType="dijit.layout.ContentPane" title="My second tab">
            Lorem ipsum and all around - second...
        </div>
        <div id="tab3" dojoType="dijit.layout.ContentPane" title="My last tab">
            Lorem ipsum and all around - last...
        </div>
    </div>
</body>

我相信dijit.byId('mainTab').selectedChildWidget应该为您提供对所选选项卡中小部件的引用(例如您的 ContentPanes 之一)。

http://www.dojotoolkit.org/api/dijit/layout/TabContainer.html#selectedChildWidget http://www.dojotoolkit.org/api/dijit/layout/TabContainer.html#selectedChildWidget

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何“获取”dijit.layout.tabcontainer 中“单击”选项卡的 ID? 的相关文章