简体   繁体   中英

Dojo: Setting a CheckBox label programmatically

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!

这不是完美的,但这里有一个如何做到的例子: http//jsfiddle.net/cBPy4/一般来说你必须记住CheckBox小部件只显示框,你必须手动处理标签...

Dojo 1.6 Firefox, Chrome

http://jsfiddle.net/cBPy4/257/

dojo.require("dijit.form.CheckBox");

dojo.ready(function(){    
    // https://bugs.dojotoolkit.org/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");
});

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