我有一個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);
});