开发者

Registering EVent Listeners inside the dojo .addOnload Method or declaraitevly

What is the difference between using registering Event Listeners inside the dojo .addOnload Method or declaraitevly registering them ??

For example i have a Button as shown

<button dojoType="dijit.form.Button" id="buttonTwo">
            Show Me!
        </button>

1st Approach :

dojo.addOnLoad(function() {
var widget = dijit.byId("butto开发者_运维问答nTwo");
dojo.connect(widget, "onClick", function(){
alert('ddddd');
});

2nd Approach :

<button dojoType="dijit.form.Button" id="buttonTwo"  onClick="callMe()">
            Show Me!
        </button>


There is no practical difference, it is a matter of how you prefer to organize your code.

Having said this, I believe you should avoid mixing declarative and programmatic approaches in Dojo, in order to have a more coherent code base. Which means if you chose the programmatic route, you should do something like this, instead of your 1st approach:

dojo.addOnLoad(function() {
    new dijit.form.Button(
        {
            label: "Show Me!", 
            onClick: function() {
                alert('ddddd');
            }
        },
        'buttonTwo'
    );
});
...
<button id="buttonTwo"></button>

This example is a full programmatic example. Depending on your preference you can use it (instead of your 1st approach), or use your second approach. You can read more about the differences in programmatic and declarative Dojo approaches here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜