Dojo单选按钮标签未显示

qjp7pelc  于 2022-12-16  发布在  Dojo
关注(0)|答案(2)|浏览(180)

我用这段代码创建了一个radioButton。

var slotDurationSettingsRow = dojo.create('tr', null, table);
    dojo.create('td', {innerHTML: 'Slot Dauer'}, slotDurationSettingsRow);
    var durationSettingsTD = dojo.create('td', {align: 'right'}, slotDurationSettingsRow);
    var durationSettingsContainer = dojo.create('div', null, durationSettingsTD);

    var radioOne = new dijit.form.RadioButton({
            label:"RadioButton1",
            value: "tea",
            name: "drink",
        },
        durationSettingsContainer);

按钮已创建,但标签属性似乎不起作用。请帮助我找到问题所在?

yk9xbfzb

yk9xbfzb1#

您需要创建一个单独的label元素,就像前面提到的@Layke。

var slotDurationSettingsRow = dojo.create('tr', null, table);

dojo.create('td', {innerHTML: 'Slot Dauer'}, slotDurationSettingsRow);

var durationSettingsTD = dojo.create('td', {align: 'right'}, slotDurationSettingsRow);

var durationSettingsContainer = dojo.create('div', null, durationSettingsTD);

var radioOne = new dijit.form.RadioButton({
    value: "tea",
    name: "drink",
}, durationSettingsContainer);

var label = dojo.create('label', {
    innerHTML: 'RadioButton1',
    for: radioOne.id
}, durationSettingsTD);

Here's a fiddle。请注意,标签附加到durationSettingsTD节点。
我也会检查the documentation fordijit/form/RadioButton,特别是示例。注意,即使是编程示例,他们也已经有了label元素,但思想是相同的。

t3irkdon

t3irkdon2#

您不能只在dijit/form/RadioButton小部件上创建一个“label”属性,您必须实际创建自己的标签并将其添加到DOM中。

AMD风格

domConstruct.create("label", {
            for: "Radio_Button_ID",                
            innerHTML: "Label Name"
        }, durationSettingsContainer);

1.6之前的旧版本〈样式

dojo.create("label", {
            for: "Radio_Button_ID",                
            innerHTML: "Label Name"
        }, durationSettingsContainer);

相关问题