乘法表没有提示

时间:2015-06-23 00:47:35

标签: javascript html

我正在制作一个不使用提示符的乘法表。

我认为代码是正确的,但不是使用我输入的数字而是返回NaN

我做错了什么?

<html>
    <head>
        <meta charset = "utf-8">
    </head>
    <body>
        <input type="text" id="num" placeholder="Insira aqui um numero de 1 a 12..."/>
        <button id="botao">Fazer tabuada</button>

        <script src="js/exercicio2.js"></script>
    </body>
</html>
var tabuada = document.getElementsByTagName("num");
var button = document.getElementById("botao");
var numero = parseInt(tabuada);

function mult() {
    for(i = 1; i < 11; i++) {
        document.write(numero + " x " + i + " = " + numero * i + "</br>");
    }
}

button.addEventListener('click', mult);

1 个答案:

答案 0 :(得分:1)

https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName

Element.getElementsByTagName()方法返回具有给定标记名称的实时HTMLCollection元素。你无法将其解析为int。如果您查看您正在返回的对象,您可以找到答案(我会提供更多 - 但看起来这是一个学习练习)。