I have a select field with id appointment_stylist_id
. For some reason, the first one of these returns my element but the second one returns开发者_开发百科 undefined
:
console.log(dojo.byId('appointment_stylist_id'));
console.log(dijit.byId('appointment_stylist_id'));
Any idea why?
This is because dojo.byId
does what you want (find a DOM element with a particular ID), and dijit.byId
doesn't do that.
dijit.byId
is a function for looking up a specific widget by its assigned name (id). This function is similar todojo.byId
but whereasdojo.byId
returns DOMNodes,dijit.byId
returns a JavaScript object that is the instance of the widget....
dijit.byId
anddojo.byId
are often confused, particularly by first time users. This function should be used when you wish to obtain a direct handle the the JavaScript object instance of your widget and access functions of that widget.
http://dojotoolkit.org/reference-guide/dijit/byId.html
See also
What the difference between dojo.byId and dijit.byId?
dojo.byId("appointment_stylist_id");
Returns the element.
dijit.byId("appointment_stylist_id");
Returns the widget.
Using dijit.byId also you can get the value of the element like:
dijit.byId("appointment_stylist_id").getValue();
精彩评论