[英]“Inspect” function (Ctrl + Shift + I) doesn't work
“if (numero.value.length == 0)”有效,但是当我添加一个数字时,程序无效,“Inspect”功能(Ctrl + Shift + I)无效,页面无效刷新。
function tabuada() { var numero = document.getElementById('txtnum') var tabuada = document.getElementById("selectTab") if (numero.value.length == 0) { window.alert("Você precisa digitar um número para que a tabuada seja gerada.") } else { var num = Number(numero.value) tabuada.innerHTML = "" for (c = 0; c = 10; c++) { var item = document.createElement('option') item.text = `${num} * ${c} = ${c * num}` tabuada.appendChild(item) } } }
<section> <div> <p> Escolha um número: <input type="number" name="num" id="txtnum"> <input type="button" value="Gerar Tabuada" onclick="tabuada()"> </p> </div> <div> <select name="tabuada" id="selectTab" size="10"></select> </div> </section>
您必须更多地查看代码:
;
在末尾。c = 10
(这总是正确的,所以你有一个无限循环)。 如果您想比较相同的东西,请使用===
或==
。 但是你必须比较c < 10
。 只要您的条件为真,循环就会迭代,因此比选择的要小。}
。 function tabuada() { var numero = document.getElementById('txtnum'); var tabuada = document.getElementById("selectTab"); if (numero.value.length == 0) { window.alert("Você precisa digitar um número para que a tabuada seja gerada."); } else { var num = Number(numero.value); tabuada.innerHTML = ""; for (c = 0; c < 10; c++) { var item = document.createElement('option'); item.text = `${num} * ${c} = ${c * num}`; tabuada.appendChild(item); } } }
<!DOCTYPE html> <html lang="pt-BR"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tabuada</title> <link rel="stylesheet" href="_estiloEx16.css"> </head> <body> <header> <h1>Tabuada</h1> </header> <section> <div> <p> Escolha um número: <input type="number" name="num" id="txtnum"> <input type="button" value="Gerar Tabuada" onclick="tabuada()"> </p> </div> <div> <select name="tabuada" id="selectTab" size="10"></select> </div> </section> <footer> <p>© Curso em vídeo</p> </footer> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.