Javascript JS中的Onclick事件在自动重置表单之前显示一秒钟的结果

Javascript JS中的Onclick事件在自动重置表单之前显示一秒钟的结果,javascript,onclick,forms,onsubmit,Javascript,Onclick,Forms,Onsubmit,这是一个简单的测验/问卷,在提交时显示测验结果。它会显示结果,但在重置页面之前只显示大约半秒钟。我还想让页面显示一个警告,如果用户在提交测验时说他们未满18岁;这不会阻止他们看到答案,只是给他们一个信息 function checkAge() { if(age<18) { alert("Always make sure you have adult supervision while caring for and handling any venomous

这是一个简单的测验/问卷,在提交时显示测验结果。它会显示结果,但在重置页面之前只显示大约半秒钟。我还想让页面显示一个警告,如果用户在提交测验时说他们未满18岁;这不会阻止他们看到答案,只是给他们一个信息

    function checkAge() {
    if(age<18) {
        alert("Always make sure you have adult supervision while caring for and handling any venomous arachnid.");
    } }

function generateAnswers() {

var choice1score = 0;
var choice2score = 0;
var choice3score = 0;
var choice4score = 0;
}

var chosenAnswers = document.getElementsByTagName('result');

for (i=0; i<chosenAnswers.length; i++) {

    if (chosenAnswers[i].checked) {
  // add 1 to that choice's score
    if (chosenAnswers[i].value == 'choice1') {
    choice1score = choice1score + 1;
    }
      if (chosenAnswers[i].value == 'choice2') {
    choice2score = choice2score + 1;
    }
    if (chosenAnswers[i].value == 'choice3') {
    choice3score = choice3score + 1;
    }
    if (chosenAnswers[i].value == 'choice4') {
    choice4score = choice4score + 1;
    }

    }
}

var maxscore = Math.max(choice1score,choice2score,choice3score,choice4score);

var resultBox = document.getElementById('result');
    if (choice1score == maxscore) { 
    resultBox.innerHTML = "Asian Forest Scorpion"
    }
    if (choice2score == maxscore) { 
    resultBox.innerHTML = "Deathstalker Scorpion"
    }
    if (choice3score == maxscore) { 
    resultBox.innerHTML = "Desert Hairy Scorpion"
    }
    if (choice4score == maxscore) { 
    resultBox.innerHTML = "Emperor Scorpion"
}

}
我把代码放在这里: 使用:

event.preventDefault();

这样可以防止网页重新加载,从而清除表单数据

毫无疑问,您只需使用event.preventDefault;停止表单标签的默认行为,即提交/发布数据。我把它放在哪里重要吗?我从未使用event.preventDefault;以前,我找到的每个答案都要求我使用jQuery,我在这段代码中没有使用jQuery。在接收数据之后,所以在.click事件或.submit与页面有用户交互的任何内容之后,您需要将事件作为参数传递,尽管我尝试将其插入onClick事件中,但在我将其放入其中后,它根本没有返回任何内容。你能给我举个例子吗?