我有一个Tab容器,当我点击一个标签的标题栏时,我想执行一些js。Dijit TabContainer事件 - onFocus
我似乎无法弄清楚如何添加一个事件。
编辑:
它看起来像我将使用onFocus,但我仍然无法找到正确的语法。
编辑:找到onFocus and onBlur,但仍然无法正常工作。
我有一个Tab容器,当我点击一个标签的标题栏时,我想执行一些js。Dijit TabContainer事件 - onFocus
我似乎无法弄清楚如何添加一个事件。
编辑:
它看起来像我将使用onFocus,但我仍然无法找到正确的语法。
编辑:找到onFocus and onBlur,但仍然无法正常工作。
您需要连接到_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);
});
其中“tabs”是您的TabContainer。
下面是一个完整的代码示例,在道场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);
});
});
});
正确的道场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);
});