我正在进行一个简单的javascript测验,我无法为我的生活获取Javascript提交表单并在同一页面打开结果,无论我是否使用location.href,open.window,或者是否我将"_self"设为目标.我做什么似乎并不重要......
function answer() {
var response = document.getElementById('answer').value;
if (response == "correctanswer")
location.href('right.html');
else
location.href('wrong.html');
}Run Code Online (Sandbox Code Playgroud)
<form onSubmit="answer()" id="answer" target="_self">
<input type="text" maxlength="55" class="box" autofocus />
<input type="submit" class="submit" value="SUBMIT" />
</form>Run Code Online (Sandbox Code Playgroud)
所以,我想发生什么,当用户提交表单,他们去"right.html"如果他们输入correctanswer到文本框中,或"wrong.html"如果他们输入任何东西.
我已经把它运行得很好了,除了这样的事实,无论我做什么,我都无法将结果页面打开_self,而是在另一个窗口中.每次.
整晚让我疯狂.