在下面的 HTML 和 JavaScript 代码中,我希望在单击按钮时动态添加文本字段和单选按钮。这工作正常。但我也希望生成的新文本字段应该具有与其上方相同的字体大小和外观,即我想要具有相同的类。
这是HTML:
<input type="radio" name="choices" value="o1"/>
<input type="text" name="o1" id="o1" class="inputtype"/>
<span class="file-wrapper">
<input type="file" name="o1_i" />
<span class="button">Choose an file</span>
</span>
<div id="responce"></div>
和 JavaScript:
var div = document.getElementById("responce");
var radio = document.createElement("input");
radio.type = "radio";
radio.name = "choices";
radio.value = "o" + countBox;
div.appendChild(radio);
var text = document.createElement("input");
text.type = "text";
text.id = "o" + countBox;
text.name ="o" + countBox;
div.appendChild(text);
var upload = document.createElement("input")
upload.type = "file";
upload.name= "o" + countBox + "_i";
div.appendChild(upload);