在javascript中使用onclick-event和document.write时,它总是必须在新窗口中打开

时间:2022-07-18 21:01:34

Does it have to open in the sam Eg:

是否必须在山姆打开例如:

function write(){ document.write("write") }

input type="button" onclick="write()" value="Click"

input type =“button”onclick =“write()”value =“点击”

2 个解决方案

#1


document.write statements must be run before the page finishes loading

必须在页面加载完成之前运行document.write语句

EDIT: Therefore, you wouldn't want to put document.write into an onclick

编辑:因此,您不希望将document.write放入onclick

If you're trying to modify a page already loaded you'll have to use div tags and use something like:

如果您正在尝试修改已加载的页面,则必须使用div标签并使用以下内容:

document.getElementById("name").innerHTML = "bob";

#2


No, it doesn't always have to open in a new window.

不,它并不总是必须在新窗口中打开。

Now, if you'll be a lot more specific I can give you a better answer.

现在,如果你会更具体,我可以给你一个更好的答案。

#1


document.write statements must be run before the page finishes loading

必须在页面加载完成之前运行document.write语句

EDIT: Therefore, you wouldn't want to put document.write into an onclick

编辑:因此,您不希望将document.write放入onclick

If you're trying to modify a page already loaded you'll have to use div tags and use something like:

如果您正在尝试修改已加载的页面,则必须使用div标签并使用以下内容:

document.getElementById("name").innerHTML = "bob";

#2


No, it doesn't always have to open in a new window.

不,它并不总是必须在新窗口中打开。

Now, if you'll be a lot more specific I can give you a better answer.

现在,如果你会更具体,我可以给你一个更好的答案。