dojo/on
http://dojotoolkit.org/reference-guide/1.9/dojo/topic.html#id3
//先是发布主题,然后订阅“相同名称”的主题,并处理发布过程中传递的参数
http://dojotoolkit.org/documentation/tutorials/1.9/events/
//事件委托:根据选择器,来集体分配事件程序


<!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="content-type" content="text/html charset=utf-8"/> <script src="dojo.js" data-dojo-config="async:true"></script> <!-- 必须要有结束符</script> --> <script> require(["dojo/on", "dojo/topic", "dojo/dom-construct", "dojo/dom", "dojo/domReady!"], function(on, topic, domConstruct, dom) { var alertButton = dom.byId("alertButton"), createAlert = dom.byId("createAlert"); on(alertButton, "click", function() { // When this button is clicked, // publish to the "alertUser" topic topic.publish("alertUser", "I am alerting you."); }); on(createAlert, "click", function(evt){ // Create another button var anotherButton = domConstruct.create("button", { innerHTML: "Another alert button",id:"mybtn" }, createAlert, "after"); topic.publish("alert2User", "I am also alerting you."); // When the other button is clicked, // publish to the "alertUser" topic /*on(anotherButton, "click", function(evt){ topic.publish("alertUser", "I am also alerting you."); });*/ }); // Register the alerting routine with the "alertUser" topic. topic.subscribe("alertUser", function(e){ alert(e); }); topic.subscribe("alert2User",function(e){ dom.byId("mybtn").innerHTML=e; }) }); </script> </head> <body> <button id="alertButton">Alert the user</button> <button id="createAlert">Create another alert button</button> </body> </html>
浙公网安备 33010602011771号