Dijit TabContainer事件 - onFocus

时间:2011-08-31 20:04:04

标签: javascript-events onclick dojo

我有一个Tab容器,当我点击标签的标题栏时,我想执行一些js。

我似乎无法弄清楚如何添加事件。


编辑:

看起来我将使用onFocus,但我仍然无法找到正确的语法。


编辑:找到了onFocus and onBlur,但仍无法让它发挥作用。

3 个答案:

答案 0 :(得分:2)

您需要连接到_transition事件。

var tabs = dijit.byId("tabs");
dojo.connect(tabs,"_transition", function(newPage, oldPage){
    console.log("I was showing: ", oldPage || "nothing");
    console.log("I am now showing: ", newPage);
});

“Tab”是TabContainer。

答案 1 :(得分:1)

这是一个完整的代码示例,适用于Dojo 1.8,我测试过它:

require(["dijit/registry",  "dojo/on", "dojo/ready", "dojo/domReady!"], function (registry, on, ready) {
    ready(function () { //wait till dom is parsed into dijits
        var panel = registry.byId('mainTab');   //get dijit from its source dom element
        on(panel, "Click", function (event) {   //for some reason onClick event doesn't work 
            alert(panel.selectedChildWidget.id);  
        });
    });
});

答案 2 :(得分:0)

正确的Dojo 1.7+应该是;

var tabs = registry.byId('someTabs');
tabs.watch("selectedChildWidget", function(name, oval, nval){
    console.log("selected child changed from ", oval, " to ", nval);
});

另一种方式可能是

var tabs = registry.byId('someTabs');
aspect.after(tabs, "selectChild", function (event) {
     console.log("You selected ", tabs.selectedChildWidget.id);
});