It is convenient to add event handlers using Dojo.connect (), without having to think about cross-browser issues. However, to use this method correctly, there are a few questions to keep in mind:
1, using Dojo.byid () to get the DOM element, and Dijit.byid () to get the Dojo widget, these two points are fundamentally different.
2, the case of the event name is critical, if the DOM element is added to the event handler, the event name is lowercase, such as the Click event, you can use the click or on
Click OK, but be sure to lowercase the C letter; If you add an event handler to the Dojo widget, the event name must conform to the Dojo specification, such as the Click event, must be written as onclick, the letter O is lowercase, and the letter C must be capitalized.
3. If you want to add an event handler to a page element, be sure to use Dojo.byid () or Dijit.byid () to get the element reference, depending on whether the element is a DOM element or a dojo widget. If it is used, the result may be a failure or an abnormal condition.
Note the above questions, the correct use of the good Dojo.connect () method is not a problem.
Example one:
<button id= "BTN" >click me!</button>
<script type= "Text/javascript" >
Dojo.connect (Dojo.byid (' btn '), ' onclick ', null, handler);
</script>
Example two:
<button id= "btn" dojotype= "Dijit.form.Button" label= "click me!" ></button>
<script type= "Text/javascript" >
Dojo.connect (Dijit.byid (' btn '), ' OnClick ', null, handler);
</script>----------------------------------------------------------------------------------------------- --------Note: This article is reproduced in: Http://blog.163.com/[email protected]/blog/static/732525372011101715346673
Considerations for adding events using Dojo.connect ()