我想插入一个按钮,该按钮将在 JavaScript 测验完成后出现。我希望该按钮与 HTML 文件中使用的按钮具有相同的样式 - 根据 CSS 表设计样式。我对 JS 不太有经验。
测验结束 JS 代码:
function endQuiz() {
$('#explanation').empty();
$('#question-image').remove();
$('#choice-block').empty();
$('#pager').empty();
$('#submitbutton').remove();
$('#question').text("You got " + score + " out of " + quiz.length + " correct. Make sure you have a grip!");
$(document.createElement('h2')).css({
'text-align': 'center',
'font-size': '4em'
}).text(Math.round(score / quiz.length * 100) +
'%').insertAfter('#question');
//button would go here
}
按钮可以在js文件中包含href类吗?
我尝试过,但失败了!提前致谢。
最佳答案
只需在 html 中编写与其他按钮相同的样式/类的最终按钮,并通过 jQuery 为其提供一个 id 供引用。
然后在 window.onload() 中或在加载页面时调用元素上的 jQuery .hide() 函数。 $('#your-button-id').hide()
测验结束后显示: $('#your-button-id').show()
这里有关 jQuery 中隐藏/显示的文档:https://www.w3schools.com/jquery/jquery_hide_show.asp
关于javascript - 添加一个按钮到 javascript 测验的末尾,使用与 HTML 文件中使用的相同样式的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54789374/