Dojo 表单处理事件
Dojo form handling events
我在 dojo 工作,我正在努力改进事件处理程序
http://dojotoolkit.org/reference-guide/1.10/dojo/on.html
我目前的申请。
http://jsfiddle.net/aGCFs/254/
on(this.resetButton, "click", function(e) {
return confirm('Press OK to reset widget values');
});
过去的工作方式。
http://jsfiddle.net/aGCFs/252/
使用 html 模板页面上的事件内联脚本。
您的代码中存在多个错误,首先您没有像这样调用 on
回调
require(["dojo/dom", "dojo/on", "dojo/domReady!"], function (dom,on) {
on(dom.byId("button"), "click", function (e) {
console.log("My button was clicked!");
});
});
你正在做的第二件事是 dom.byId("button")
你没有带有 id 按钮的按钮,所以你需要指定一个特定的按钮 ID。像这样:
require(["dojo/dom", "dojo/on", "dojo/domReady!"], function (dom,on) {
on(dom.byId("nextTab"), "click", function (e) {
console.log("My button was clicked!");
});
});
勾选 jsffidle .
如果您单击下一个选项卡按钮,它将显示控制台日志消息
需要在require函数中添加ready模块。然后在回调中用ready模块调用整个代码。
require([
"dojo/ready", // add the ready module
"dojo/parser",
"dojo/on",
"dijit/registry",
"dijit/layout/ContentPane",
"dijit/layout/TabContainer",
"dijit/form/ValidationTextBox",
"dijit/form/DateTextBox",
"dijit/form/Select",
"dijit/form/Form",
"dijit/form/Button",
"dojo/domReady!"], function (ready, parser, on, registry, ContentPane) {
// call your the code in the callback.
ready( function() {
var progTabCounter = 1;
makeTab = function () {
var tc = registry.byId("mainTabContainer");
var cp = new ContentPane({
title: 'Programmatically created tab ' + (progTabCounter++),
closable: true
});
cp.domNode.innerHTML = "I was created programmatically!";
tc.addChild(cp, 0);
};
prevTab = function () {
var tc = registry.byId("mainTabContainer");
console.log("prev tab", tc);
var currIndex = tc.getIndexOfChild(tc.selectedChildWidget);
var tabs = tc.getChildren();
if (currIndex > 0) {
tc.selectChild(tabs[currIndex - 1]);
}
};
nextTab = function () {
var tc = registry.byId("mainTabContainer");
console.log("next tab", tc);
var currIndex = tc.getIndexOfChild(tc.selectedChildWidget);
var tabs = tc.getChildren();
if (currIndex < tabs.length - 1) {
tc.selectChild(tabs[currIndex + 1]);
}
};
registry.byId("resetButton").on("click", function(e) {
console.log("clicked on reset");
return confirm('Press OK to reset widget values');
});
}); // end of ready call
});
我在 dojo 工作,我正在努力改进事件处理程序
http://dojotoolkit.org/reference-guide/1.10/dojo/on.html
我目前的申请。 http://jsfiddle.net/aGCFs/254/
on(this.resetButton, "click", function(e) {
return confirm('Press OK to reset widget values');
});
过去的工作方式。
http://jsfiddle.net/aGCFs/252/
使用 html 模板页面上的事件内联脚本。
您的代码中存在多个错误,首先您没有像这样调用 on
回调
require(["dojo/dom", "dojo/on", "dojo/domReady!"], function (dom,on) {
on(dom.byId("button"), "click", function (e) {
console.log("My button was clicked!");
});
});
你正在做的第二件事是 dom.byId("button")
你没有带有 id 按钮的按钮,所以你需要指定一个特定的按钮 ID。像这样:
require(["dojo/dom", "dojo/on", "dojo/domReady!"], function (dom,on) {
on(dom.byId("nextTab"), "click", function (e) {
console.log("My button was clicked!");
});
});
勾选 jsffidle .
如果您单击下一个选项卡按钮,它将显示控制台日志消息
需要在require函数中添加ready模块。然后在回调中用ready模块调用整个代码。
require([
"dojo/ready", // add the ready module
"dojo/parser",
"dojo/on",
"dijit/registry",
"dijit/layout/ContentPane",
"dijit/layout/TabContainer",
"dijit/form/ValidationTextBox",
"dijit/form/DateTextBox",
"dijit/form/Select",
"dijit/form/Form",
"dijit/form/Button",
"dojo/domReady!"], function (ready, parser, on, registry, ContentPane) {
// call your the code in the callback.
ready( function() {
var progTabCounter = 1;
makeTab = function () {
var tc = registry.byId("mainTabContainer");
var cp = new ContentPane({
title: 'Programmatically created tab ' + (progTabCounter++),
closable: true
});
cp.domNode.innerHTML = "I was created programmatically!";
tc.addChild(cp, 0);
};
prevTab = function () {
var tc = registry.byId("mainTabContainer");
console.log("prev tab", tc);
var currIndex = tc.getIndexOfChild(tc.selectedChildWidget);
var tabs = tc.getChildren();
if (currIndex > 0) {
tc.selectChild(tabs[currIndex - 1]);
}
};
nextTab = function () {
var tc = registry.byId("mainTabContainer");
console.log("next tab", tc);
var currIndex = tc.getIndexOfChild(tc.selectedChildWidget);
var tabs = tc.getChildren();
if (currIndex < tabs.length - 1) {
tc.selectChild(tabs[currIndex + 1]);
}
};
registry.byId("resetButton").on("click", function(e) {
console.log("clicked on reset");
return confirm('Press OK to reset widget values');
});
}); // end of ready call
});