我使用此代码创建一个单选按钮。
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);
创建按钮但标签属性似乎不起作用。请帮我找到问题?
答案 0 :(得分:1)
您需要创建一个单独的标签元素,例如@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 for dijit/form/RadioButton
,尤其是示例。请注意,即使使用程序化示例,它们也已经有label
个元素,但这个想法是一样的。
答案 1 :(得分:0)
您不能只在dijit / form / RadioButton小部件上创建“label”属性。您必须实际创建自己的标签并将其添加到DOM。
domConstruct.create("label", {
for: "Radio_Button_ID",
innerHTML: "Label Name"
}, durationSettingsContainer);
dojo.create("label", {
for: "Radio_Button_ID",
innerHTML: "Label Name"
}, durationSettingsContainer);