我想使用 JavaScript 和 jQuery 动态创建一个按钮。
下面的代码是测验的最后一部分,当测验完成时,它会给出结果并说明您已完成。我想在此期间使用 JS 动态创建一个按钮,将用户带回主页 (index.html)。
非常感谢任何帮助。
function displayFinalSlide(){
$(stage).append('<div class="questionText">You have finished the quiz!<br><br>Total questions: '+numberOfQuestions+'<br>Correct answers: '+score+'</div>');
}//display final slide
最佳答案
试试这个:就像添加 html 一样,只需添加 anchor 标记/按钮即可
function displayFinalSlide(){
$(stage).append('<div class="questionText">You have finished the quiz!<br><br>Total questions: '+numberOfQuestions+'<br>Correct answers: '+score+'</div><a href="index.html">Index Page</a>'); // here in href you can give the path where you want to redirect to
}
关于Javascript - 动态创建按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30316642/