Markdown 测验:逐题反馈和可复查答案
覆盖来源20类基础目标,纠正多正确答案和扩展语法的含混题。
学完这一章,你能够
- 覆盖来源20类基础目标,纠正多正确答案和扩展语法的含混题。
- 覆盖来源20类基础目标,纠正多正确答案和扩展语法的含混题。
题目范围与准确答案
覆盖标记语言、标题、链接、图片、粗斜体、无序/有序、引用、围栏、水平线、表格分隔、行内代码、图片!、六级、任务、居中、删除线、硬换行和扩展名。题干明确是基础规范还是扩展,不把两种有效语法强行只有一项正确。
反馈、计分和重试
每题选择后确认,显示正确性与原因;允许前后切换,修改选择需重新确认。总分按最后已确认答案计算,不因重复点击累计得分;未作答不能显示已完成。重新开始清空全部选择与记录。
本地页面不提交个人信息,不将学习测验当账号考试成绩。20题全部正确、全部错误、改答、漏答、边界导航及重启均需实际观察。
特别修正
.md和.markdown是常见约定,.txt也能装同样文本但不是“所有平台自动识别Markdown”的保证。尖括号URL和标准内联链接都可能有效,硬换行也不只有两个空格一种;题目不能用错误选项排除本来合法语法。
语法、作用与边界
| 形式/能力 | 作用 | 条件及限制 |
| 20个基础目标 | 逐题反馈 | 语法/扩展题干明确 |
| 确认/改答 | 最后确认答案计分 | 改选后需重确认 |
| 前/后导航 | 保存当前状态 | 首尾按钮禁用 |
| 结束/重启 | 完整性/清空 | 漏答不完成,重复确认不加分 |
| 常见扩展名与多合法形式 | 纠正含混选项 | .txt内容不等于自动识别 |
本章独立核心源码与验证步骤
展开查看收起
javascript
export function mountQuiz(root,questions){
const state={index:0,choices:Array(questions.length).fill(null),confirmed:Array(questions.length).fill(false)};
const heading=document.createElement('h2'),progress=document.createElement('p'),options=document.createElement('fieldset'),feedback=document.createElement('p'),confirm=document.createElement('button'),previous=document.createElement('button'),next=document.createElement('button'),finish=document.createElement('button'),restart=document.createElement('button'),result=document.createElement('p');
progress.id='quiz-progress';heading.id='quiz-question';options.id='quiz-options';feedback.id='quiz-feedback';feedback.setAttribute('role','status');result.id='quiz-result';result.setAttribute('role','status');confirm.id='quiz-confirm';previous.id='quiz-previous';next.id='quiz-next';finish.id='quiz-finish';restart.id='quiz-restart';confirm.textContent='确认答案';previous.textContent='上一题';next.textContent='下一题';finish.textContent='查看结果';restart.textContent='重新开始';
root.append(progress,heading,options,feedback,confirm,previous,next,finish,restart,result);
function draw(){const q=questions[state.index];progress.textContent=`第${state.index+1}/${questions.length}题`;heading.textContent=q.question;options.replaceChildren();const legend=document.createElement('legend');legend.textContent='选择一个答案';options.append(legend);q.options.forEach((value,i)=>{const label=document.createElement('label'),input=document.createElement('input');input.type='radio';input.name='quiz-answer';input.value=String(i);input.checked=state.choices[state.index]===i;input.addEventListener('change',()=>{state.choices[state.index]=i;state.confirmed[state.index]=false;feedback.textContent='答案已修改,请重新确认';result.textContent=''});label.append(input,document.createTextNode(value));options.append(label)});feedback.textContent=state.confirmed[state.index]?((state.choices[state.index]===q.correct?'回答正确。':'回答有误。')+q.explanation):'请选择并确认';previous.disabled=state.index===0;next.disabled=state.index===questions.length-1;}
confirm.onclick=()=>{if(state.choices[state.index]===null){feedback.textContent='请先选择答案';return}state.confirmed[state.index]=true;draw()};previous.onclick=()=>{if(state.index>0){state.index--;draw()}};next.onclick=()=>{if(state.index<questions.length-1){state.index++;draw()}};finish.onclick=()=>{const done=state.confirmed.filter(Boolean).length;if(done!==questions.length){result.textContent=`尚有${questions.length-done}题未确认`;return}const score=questions.reduce((sum,q,i)=>sum+(state.choices[i]===q.correct?1:0),0);result.textContent=`完成:${score}/${questions.length}`};restart.onclick=()=>{state.index=0;state.choices.fill(null);state.confirmed.fill(false);result.textContent='';draw()};draw();return{snapshot:()=>structuredClone(state)};
}
查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包
- 实际20题,全部正确20/20、全部错误0/20、改答19/20分别观察。
- 漏答不完成,重复确认不多计,首尾导航正确,重启清空。
本章附件与实例包
课程关联工程包(登记关联18章) · 含当前章节或实例 · mbskycom202611a519.zip
常见错误与边界检查
- 把宿主扩展当成基础规范。
- 自动清理空白改变硬换行或代码示例。
- 图片/源码存在不等于全部知识点和桌面软件操作已验收。
技术规范与官方资料
练习与参考解答
查看参考解答
保留准确源文并核对选定规范、上下文及扩展配置,不以视觉相似替代结构。