开发者

Add labels programmatically

I have one div id="container" container and I need to add labels to that开发者_高级运维 div ( 10 or 4 or one - depends which button I click ) and need to look like table ( rows x 2 column ). How to achieve this ? How to add labels programmatically ?


You can use dojo.create function. E.g.:

var label = dojo.create("label", {for:"fieldId", innerHTML:"SomeText"}, "tableCellId");

where tableCellId - id of the element in which you want to append label

Similarly you can dynamically create a table, and add labels to a new table.

var table = dojo.create("table", null, dojo.body());
var row = dojo.create("tr", null, table);
var cell = dojo.create("td", null, row);
var label = dojo.create("label", {for:"fieldId", innerHTML:"SomeText"}, cell);

Dojo create documentation


Here's how I've been doing it in dojo.

dojo.place('<label for="field">Field Name</label>', dojo.byId('widget_fieldId'), 'before');


I found I needed to add the label to the container prior to creating the TextEntry element but referenced the TextEntry element's id.

Below is an example where I added a label for an editor:

var tabWizard = new TabContainer({
   id : "tabWizard",
   class : "centerTabContainer",
   tabPosition : "left"
});
var tab = new ContentPane({
   title : "tabTitles",
   class : "tabPage"
});
tabWizard.addChild(tab);
var tabContainer = new BorderContainer({
   design : 'headline',
   gutters : false
});
var tabMain = new ContentPane(
   {
      id : "tabMain_What",
      class : "cdmMain",
      region : "center"
   });
tabMain.startup();
// here is where the label is created referencing the id details
tabMain.domNode.appendChild(
   dojo.create("label",{
      "for" : "details", innerHTML : "Details:" 
    })
);
// here is the editor to be labeled as "Details:"
var tabPrompt = new Editor({
   id : "details",
   name : "details",
   class : "details"
});
tabMain.addChild(tabPrompt);
tabContainer.addChild(tabMain);
tab.addChild(tabContainer);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜