我正在尝试创建一个动态表单,因此单击一个按钮我调用了一个 Javascript 函数。这是功能:
function addradiobutton(type){
var element = document.createElement("input");
//Assign different attributes to the element.
element.setAttribute("type", type);
element.setAttribute("value", type);
element.setAttribute("name", type);
var foo = document.getElementById("fooBar");
//Append the element in page (in span).
foo.appendChild(element);
counter=counter+1;
}
这段代码添加了一个单选按钮,它的标签是这样的
<input type="radio" name="radio" value="radio">
但我想让这段代码像这样。
<input type="radio" name="radio" value="radio">WATER</input>
我不介意关闭输入标签,但我想在代码末尾获得值“水”。
仅以水为例,它的价值也是动态的。
我应该怎么办 ?