1

I want to use javascript document.write in an if statement. So far when I do this, it writes what is supposed to be in the document.write on a new blank page. I want to figure out how to make it so that the text that is supposed to be written is printed on the same page rather than a new blank page.

4

2 回答 2

2

这与处于if语句中无关,它与document.write文档处于关闭状态时使用有关。然后使用它将打开一个要写入的新文档。没有办法解决这个问题。

使用DOM 操作而不是document.write.

于 2013-07-24T15:51:32.257 回答
1

Document.write只能在文档仍在加载时使用,因此之后任何尝试使用它都意味着它将写入新文档。

您需要设置元素的innerHTML

于 2013-07-24T15:54:28.597 回答