最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dojo: Setting a CheckBox label programmatically - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 5

It'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");
});
发布评论

评论列表(0)

  1. 暂无评论