开发者

dojo.byId() works but dijit.byId() doesn't

开发者 https://www.devze.com 2023-02-27 08:54 出处:网络
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:

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 to dojo.byId but whereas dojo.byId returns DOMNodes, dijit.byId returns a JavaScript object that is the instance of the widget.

...

dijit.byId and dojo.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();
0

精彩评论

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