javascript - 添加一个按钮到 javascript 测验的末尾,使用与 HTML 文件中使用的相同样式的按钮

标签 javascript jquery html button

我想插入一个按钮,该按钮将在 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/

相关文章:

java - 隐藏字段值空白 Thymeleaf

php - 在 foreach 循环中从多维数组中获取键和值 (PHP/HTML)

javascript - 谷歌驱动器公共(public)

javascript - 每分钟从文本文件中获取数据并更新网页

javascript - 加速器。检测导航栏标题上的点击

javascript - 具有 jQuery 动态表单的单个 div 中的多个文本字段

javascript - 使用 jQuery 选择具有特定类的第一个和最后一个元素

javascript - InDesign 脚本 : footnotes loosing their style

javascript - typescript - 创建表示偶数集的类型

javascript - 是否可以从任何已加载 jquery 的页面向 google.com 发出成功的 ajax get 请求?