fix: 修复多选问题提交后选中项不显示高亮的问题

This commit is contained in:
Roe-xin
2026-03-06 09:08:38 +08:00
parent ea19dfcbe6
commit 5e9083041f

View File

@ -1211,7 +1211,7 @@ export function getMessageAreaScript(): string {
const optionsHtml = q.options.map(opt => { const optionsHtml = q.options.map(opt => {
const isSelected = selectedAnswers.includes(opt); const isSelected = selectedAnswers.includes(opt);
return \`<label style="display:flex;align-items:center;gap:6px;cursor:pointer;padding:4px 0;"> return \`<label class="question-option\${isSelected ? ' selected' : ''}" style="display:flex;align-items:center;gap:6px;cursor:pointer;padding:4px 0;">
<input type="\${inputType}" name="\${inputName}" value="\${opt}" \${isSelected ? 'checked' : ''} \${isAnswered ? 'disabled' : ''}> <input type="\${inputType}" name="\${inputName}" value="\${opt}" \${isSelected ? 'checked' : ''} \${isAnswered ? 'disabled' : ''}>
<span>\${opt}</span> <span>\${opt}</span>
</label>\`; </label>\`;
@ -1729,9 +1729,18 @@ export function getMessageAreaScript(): string {
// 标记问题已回答 // 标记问题已回答
segmentDiv.classList.add('answered'); segmentDiv.classList.add('answered');
// 禁用所有输入 // 禁用所有输入并保持选中状态的高亮
const inputs = segmentDiv.querySelectorAll('input'); const inputs = segmentDiv.querySelectorAll('input');
inputs.forEach(input => input.disabled = true); inputs.forEach(input => {
input.disabled = true;
// 确保选中的选项保持高亮
if (input.checked) {
const label = input.closest('.question-option');
if (label) {
label.classList.add('selected');
}
}
});
// 隐藏提交按钮 // 隐藏提交按钮
const submitBtn = segmentDiv.querySelector('.custom-submit'); const submitBtn = segmentDiv.querySelector('.custom-submit');