简体   繁体   中英

Dynamically render dojo checkbox

Why does a checkbox created using the javascript and placed in DOM Tree using dojo.place() render as an input[type="text"] instead of an input[type="checkbox"] element?

generated HTML code :

<input id="baseCalcRoundCustomized" 
name="hierarchicalRounding.baseCalcRoundCustomized" 
value="0" dojoType="dijit.form.CheckBox" class="pcheckbox" 
onchange="checkValue(this.id)" unchecked />

When you dynamically add DOM nodes, they will not be converted into Dojo widgets (dijit). To become such a widget (dijit), the DOM node needs to be parsed. If you setup your web application to use parseOnLoad , it will parse the HTML page automatically when loading the webpage, that's why widgets added this way will work properly.

There are two options:

The first one is by parsing the newly added DOM nodes by yourself using the dojo/parser module. You can parse the page again using the parse() function, but you can also specify a DOM node which should be parsed. More information about this module can be found at the API docs or the reference guide .

Another way (and I recommend this one), is by programmatically adding the widget in stead of adding just a DOM node and parsing it. You can read more about this at the reference guide .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM