开发者

How do you test whether a tab is active with dojo tabs

How do you test whether a tab is active or not with a dojo tab container? (In JQuery this is simple... you can use so开发者_如何学运维mething like this

if($("#accordion").accordion('option', 'active') == mytabNumber){

With dojo's, dijit.layout.TabContainer there must be a similiar way to do it without having to write a litener function and all that jazz.

perhaps something like...

if( dojo.byId("tab2"), {selected:true} ){

Thanks in advance!


You can compare the widget for the tab with the tab container's selectedChildWidget property, i.e.:

dijit.byId('tabContainer').selectedChildWidget == dijit.byId('tab2')


If you have a reference to the tab already, you can simply just check its 'selected' property to see if it's selected, regardless of the container it is in.

var tab2 = dijit.byId('tab2');
if (tab2.get('selected')) { /* do stuff */ }

I've created a more detailed example at http://jsfiddle.net/brianarn/ws28T/


Here's more complete code answer that gives the surrounding code for Dojo 1.8:

require(["dijit/registry",  "dojo/ready", "dojo/domReady!"], function (registry, ready) {
    ready(function () { //wait till dom is parsed into dijits
        if (dijit.byId('tabContainer').selectedChildWidget == dijit.byId('tab2'))
            alert('Yes, we found it!');
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜