简体   繁体   English

“检查”功能(Ctrl + Shift + I)不起作用

[英]“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:您必须更多地查看代码:

  • Every opnening tag needs a closing one.每个开始标签都需要一个结束标签。 /BODY and /HTML was missing. /BODY 和 /HTML 丢失。
  • Every line in Javascript needs a ; Javascript 中的每一行都需要一个; at the end.在末尾。
  • The condition of your for-loop was wrong.你的 for 循环的条件是错误的。 You made an allocation 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.只要您的条件为真,循环就会迭代,因此比选择的要小。
  • Your function needs a closing } .您的功能需要结束}

 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>&copy; Curso em vídeo</p> </footer> </body> </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM