为什么我的按钮使我的功能在不同的 window 中打开?
Why does my button make my function open in a different window?
我试图让我的代码在同一个 window 中执行我的函数,但它总是用一个只运行该函数的新代码覆盖当前的 window,当然这给我带来了程序完全停止。如何更改我的代码以使其在相同的 window 中打开? (Java 的新手)
<button onclick="blackFemale()">Black Female</button>
<script>
document.write("Click the button of the character you would like to be, then click play.");
function blackFemale() {
character = "black female";
document.write("You are a ", character, ".");
var x = document.createElement("IMG");
x.setAttribute("src", "IntroImages/FemaleBlack.jpg");
x.setAttribute("width", "304");
x.setAttribute("width", "228");
x.setAttribute("alt", "black female");
document.body.appendChild(x);
}
不胜感激,刚问这个问题的时候很紧张,呵呵
document.write
覆盖整个 page.you 可以将其附加到正文。
<button onclick="blackFemale()">Black Female</button>
js:
function blackFemale() {
character = "black female";
var text =document.createTextNode("You are a " + character + ".");
document.body.appendChild(text);
var x = document.createElement("IMG");
x.setAttribute("src", "IntroImages/FemaleBlack.jpg");
x.setAttribute("width", "304");
x.setAttribute("width", "228");
x.setAttribute("alt", "black female");
document.body.appendChild(x);
}
我试图让我的代码在同一个 window 中执行我的函数,但它总是用一个只运行该函数的新代码覆盖当前的 window,当然这给我带来了程序完全停止。如何更改我的代码以使其在相同的 window 中打开? (Java 的新手)
<button onclick="blackFemale()">Black Female</button>
<script>
document.write("Click the button of the character you would like to be, then click play.");
function blackFemale() {
character = "black female";
document.write("You are a ", character, ".");
var x = document.createElement("IMG");
x.setAttribute("src", "IntroImages/FemaleBlack.jpg");
x.setAttribute("width", "304");
x.setAttribute("width", "228");
x.setAttribute("alt", "black female");
document.body.appendChild(x);
}
不胜感激,刚问这个问题的时候很紧张,呵呵
document.write
覆盖整个 page.you 可以将其附加到正文。
<button onclick="blackFemale()">Black Female</button>
js:
function blackFemale() {
character = "black female";
var text =document.createTextNode("You are a " + character + ".");
document.body.appendChild(text);
var x = document.createElement("IMG");
x.setAttribute("src", "IntroImages/FemaleBlack.jpg");
x.setAttribute("width", "304");
x.setAttribute("width", "228");
x.setAttribute("alt", "black female");
document.body.appendChild(x);
}