You may try something like this:
require(["dojo/on", "dojo/dom", "dojo/domReady!"],
function(on, dom) {
var newActButton = dom.byId("newActButton");
on(newActButton, "click", newActButtonOnClick);
});
Domanda
I m trying to set a on click event dynamically to a dijit/form/Button. But, the method I m trying doesn't seem to work.
<button id = "newActButton" data-dojo-type="dijit/form/Button"
type = "button"
data-dojo-props="iconClass: 'newActButtonIcon', label: 'New Act'"></button>
dijit.byId("newActButton").set("onClick", newActButtonOnClick());
I have a function newActButtonOnClick(), which I want to fire.
Soluzione
You may try something like this:
require(["dojo/on", "dojo/dom", "dojo/domReady!"],
function(on, dom) {
var newActButton = dom.byId("newActButton");
on(newActButton, "click", newActButtonOnClick);
});
Altri suggerimenti
It doesn't work because you have an error in your code (by.Id VERSUS byId):
dijit.by.Id("newActButton").set("onClick", newActButtonOnClick());
should be
dijit.byId("newActButton").set("onClick", newActButtonOnClick());
EDIT
Try this:
require(["dojo/parser", "dijit/form/Button"]);
<button data-dojo-type="dijit/form/Button" type="button">Click me too!
<script type="dojo/on" data-dojo-event="click" data-dojo-args="evt">
require(["dojo/dom"], function(dom){
dom.byId("result2").innerHTML += "Thank you! ";
});
</script>
</button>
<div id="result2"></div>