admin管理员组文章数量:1320633
Let me preface by saying that I saw this other question on the subject of CheckBox labels that was asked and answered well over a year ago.
I was confused by the answers and am hoping that someone can clarify or that there has been new dojo functionality introduced since then that allows me to do this without resorting to HTML.
So without further ado, I would like to know how to programmatically create labels for check boxes.
I have a check box like so:
this.pubBoxId = new dijit.form.CheckBox({
label: "IdChannel",
checked: false,
channel: that.idChannel
}, that.name + "_PBI");
As you can see I've tried to edit the "label" field, but the label never actually shows up on the page. I have multiple CheckBoxes that I am adding to a ContentPane and simply want a label to the left or right of the check box. Is there any way I can do this without having to write separate HTML?
Also, making a separate ContentPane for each individual label would be a big pain because of how many CheckBoxes I plan to have.
Thank you for reading, and let me know if further clarification is needed!
Let me preface by saying that I saw this other question on the subject of CheckBox labels that was asked and answered well over a year ago.
I was confused by the answers and am hoping that someone can clarify or that there has been new dojo functionality introduced since then that allows me to do this without resorting to HTML.
So without further ado, I would like to know how to programmatically create labels for check boxes.
I have a check box like so:
this.pubBoxId = new dijit.form.CheckBox({
label: "IdChannel",
checked: false,
channel: that.idChannel
}, that.name + "_PBI");
As you can see I've tried to edit the "label" field, but the label never actually shows up on the page. I have multiple CheckBoxes that I am adding to a ContentPane and simply want a label to the left or right of the check box. Is there any way I can do this without having to write separate HTML?
Also, making a separate ContentPane for each individual label would be a big pain because of how many CheckBoxes I plan to have.
Thank you for reading, and let me know if further clarification is needed!
Share Improve this question edited May 23, 2017 at 10:24 CommunityBot 11 silver badge asked Jun 20, 2012 at 21:13 Mitchell FlahertyMitchell Flaherty 1023 silver badges8 bronze badges2 Answers
Reset to default 5It's not perfect but here is an example on how you can do it : http://jsfiddle/cBPy4/ In general you have to remember that CheckBox widget will just display the box, you have to handle the label manually...
Dojo 1.6 Firefox, Chrome
http://jsfiddle/cBPy4/257/
dojo.require("dijit.form.CheckBox");
dojo.ready(function(){
// https://bugs.dojotoolkit/ticket/11611
var widgetNode = dojo.doc.createElement("DIV");
chk = dojo.create("input", {id:"cbox", type:"checkbox"}, widgetNode);
lbl = dojo.create("label", {innerHTML:"Check me", "for":"cbox"}, widgetNode);
dojo.style(lbl, "marginLeft", ".5em");
var cbWidget = new dijit.form.CheckBox({}, chk);
cbWidget.startup();
cbWidget.domNode.appendChild(lbl);
dojo.place(cbWidget.domNode, "container");
});
本文标签: javascriptDojo Setting a CheckBox label programmaticallyStack Overflow
版权声明:本文标题:javascript - Dojo: Setting a CheckBox label programmatically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742076072a2419418.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论