[英]“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.