最近我一直试图制作一个Yes / No 8球,因为我没有别的事可做。我花了很多时间对它进行编码并使其完美运行,但另一个想法突然出现在我脑海中。如果我尝试使用此代码制作书签,该怎么办?所以我研究了如何将HTML附加到用window.open()方法打开的窗口中。我尝试了所有我能找到但无济于事的东西。所以,我现在在这里,输入这个问题寻求帮助。理解此代码也包含脚本标记。
HTML我想附加到空白窗口:
document.getElementById('main').onclick = yesNo();
document.getElementById('autoclear').onclick = autoClear();
function autoClear(button) {
if (button.value == "Autoclear (on)") {
button.value = "Autoclear (off)";
} else {
button.value = "Autoclear (on)";
}
}
function yesNo() {
var yesno = ["Yes", "No", "Maybe"];
var random = yesno[Math.floor(Math.random() * yesno.length)];
var question = document.getElementById('question').value;
var output = document.getElementById('output');
if (question == '') {
output.innerHTML = "Please enter a question!";
} else {
output.innerHTML = "The answer to " + "'" + question + "'" + " is: " + random;
autoClearQuestion();
}
}
function autoClearQuestion() {
var button = document.getElementById('autoclear').value.toString();
if (button.includes("on")) {
question.value = "";
}
}
function clearQuestion() {
question.value = "";
}

<p id="test"> Ask your question below.
<br>
<span>
<input id="question" type=text value="Is my friend gay?">
<br>
<input id="main" type=button value="Yes or no? Find out by clicking" onClick=yesNo()>
<br>
<input id="autoclear" type=button value="Autoclear" onClick=autoClear(this)>
<input id="clear" type=button value="Clear Question" onClick=clearQuestion()>
<br>
</span>
</p>
<p id="output"> </p>
&#13;
回顾:我想制作一个Javascript书签。这个书签必须打开一个窗口,上面附有上面提到的代码。
凸块