我有一个ID为appointment_stylist_id
的选择字段。由于某种原因,第一个返回我的元素,但是第二个返回undefined
:
console.log(dojo.byId('appointment_stylist_id'));
console.log(dijit.byId('appointment_stylist_id'));
知道为什么吗?
最佳答案
这是因为dojo.byId
完成了您想要的(找到具有特定ID的DOM元素),而dijit.byId
却没有做到。
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
也可以看看
What the difference between dojo.byId and dijit.byId?
关于dojo - dojo.byId()有效,但dijit.byId()不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5724147/