Document.write function replaces the whole page with the text

巧了我就是萌 提交于 2019-11-28 14:28:30

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:

<div id="answer"></div>

...and then:

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

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

If you add an empty element like <span id="fillme"></span> to the document you can use this with var fillme = document.getElementById("fillme"); and then later assign content to fillme with fillme.innerHTML = answer;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!