1 回答
TA贡献1779条经验 获得超6个赞
如果有人感兴趣,这就是我解决这个问题的方法:
function submitDecision(){
const decisionForm = document.querySelectorAll('[name^=decisionOptions]');
for (const selector of decisionForm){
const rejectSelector = selector.parentNode.lastElementChild.previousElementSibling;
const formDiv = selector.parentNode
const brTag = formDiv.nextElementSibling;
const errorMsg = document.createElement('p');
errorMsg.className = 'error-msg float-right';
errorMsg.innerHTML = 'Please make a selection before submitting';
errorMsg.style.color = 'red';
if ((selector.value == "shortlist" && selector.checked == false) && (rejectSelector.checked == false)){
console.log(`no options selected for application-no${formDiv.dataset.applicationNo}`);
formDiv.parentNode.insertBefore(errorMsg, brTag.nextElementSibling);
selector.addEventListener('change', () => {
if (selector.checked){
console.log("remove error message");
try {
errorMsg.remove()
} catch(err){
console.log(err)
}
}
})
rejectSelector.addEventListener('change', () => {
if (rejectSelector.checked){
console.log("remove error message");
try {
errorMsg.remove()
} catch(err){
console.log(err)
}
}
})
}
}
}
我不知道它本身是否写得高效,但它确实能完成工作。
添加回答
举报