Document.write function replaces the whole page with the text

前端 未结 2 1850
無奈伤痛
無奈伤痛 2020-12-12 04:28

I am relatively new to javascript and I created a function to multiply two numbers together, but document.write replaces the whole page with the answer. I know

2条回答
  •  青春惊慌失措
    2020-12-12 05:31

    You already know how to use document.getElementById() to retrieve the values of inputs on your page. So do something similar to update an element that holds the answer:

    ...and then:

    document.getElementById("answer").innerHTML = answer;
    

    Simle demo: http://jsfiddle.net/V5R5h/1/

提交回复
热议问题