2 回答
TA贡献1831条经验 获得超9个赞
您似乎要添加带有单选按钮的数字值作为文本的行,然后将每一行从数字转换为“ *”。为什么不在添加行之前转换为'*'?然后,您只需要一个功能。
const radio = document.getElementsByName("gender");
const boton = document.getElementById("btnBoton");
const listado = document.getElementById('contenedor-filas');
boton.addEventListener('click', enviaNumeros);
function enviaNumeros()
{
radio.forEach(function(elementos){
if(elementos.checked)
{
estrellas = document.createElement('h3');
let s = '';
for (let i = 0; i < elementos.value; i++) {
s += '*';
}
estrellas.textContent = s;
listado.appendChild(estrellas);
}
});
}
<div class="container-fluid">
<div class="row">
<input type="radio" name="gender" value="5" id="radio5"> 5<br>
<input type="radio" name="gender" value="4" id="radio4"> 4<br>
<input type="radio" name="gender" value="3" id="radio3"> 3<br>
<input type="radio" name="gender" value="2" id="radio2"> 2<br>
<input type="radio" name="gender" value="1" id="radio1"> 1<br>
<input type="submit" value="enviar" id="btnBoton">
</div>
</div>
<section class="lista-comentarios">
<div class="container-fluid" id="contenedor-filas">
<h1>Comment List</h1>
</div>
</section>
添加回答
举报