我无法弄清楚如何使用javascript动态创建的标签垂直显示单选按钮。我的收音机按钮显示在线。这是我的代码...... CSS / display:list-item;不起作用...... 谢谢你的帮助!
<script type = "text/javascript">
var form = document.createElement("myForm");
for (i=0; i<myArray.length; i++) {
x=myArray[i];
addradiobutton("radio",x,"myForm");
}
function addradiobutton(type,text,formName) {
var label = document.createElement("label");
var element = document.createElement("input");
element.setAttribute("type", type);
element.setAttribute("value", text);
element.setAttribute("name", formName);
label.appendChild(element);
label.innerHTML += text;
var foo = document.getElementById(formName);
foo.appendChild(label);
}
</script>
答案 0 :(得分:0)
function addradiobutton() {
var result=""
for(i=0;i<3;i++){
result+="<label>" + i + "</label><input type='radio' name='radio'>";
}
$('form').append(result);
}