【发布时间】:2015-08-24 16:58:56
【问题描述】:
我是 Javascript 新手。我有一个问题,如何使用 javascript 在单选按钮旁边自动添加文本。我有以下代码:
for (var index=0; index<4; index++)
{
var text = "Hello" + index;
var name = 'RadioButton' + (index+1);
var radioBut = document.createElement('input');
radioBut.setAttribute('type', 'radio');
radioBut.setAttribute('name', name);
document.body.appendChild(radioBut);
var newdiv = document.createElement('div');
var divIdName = 'my'+index+'Div';
newdiv.setAttribute('id',divIdName);
document.body.appendChild(newdiv);
newdiv.innerHTML = text;
}
它打印单选按钮,但文本显然打印在下面。我必须做什么才能获得以下格式:RadioButton + Text?
【问题讨论】:
-
请包含html输出
标签: javascript button text radio-button