[英]“Inspect” function (Ctrl + Shift + I) doesn't work
The "if (numero.value.length == 0)" works, but when I add a number the program doesn't work, the "Inspect" function (Ctrl + Shift + I) doesn't work and the page does not refresh. “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>
You had to look more on your code:您必须更多地查看代码:
;
;
at the end.c = 10
(which is allways true, so you have an infinite loop).c = 10
(这总是正确的,所以你有一个无限循环)。 If you want to compare something on equal use ===
or ==
.===
或==
。 But you had to compare for c < 10
.c < 10
。 The loop will as long iterate as your condition is true so smaller than is the choice.}
.}
。 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.