提问人:Kaustubh Maladkar 提问时间:6/8/2022 更新时间:8/12/2022 访问量:196
仅在未发现错误时启用提交按钮
Enable submit button only when no error is found
问:
我有一个简单的应用程序,我只想在未发现错误时启用计算按钮(如果值不是数字或值小于 0,则记录错误)。我使用 && 和 || 执行一些条件检查算子。但是,当只有一个输入正确填充且没有错误时,该按钮将启用。但是,当指定了显式错误值时,该按钮将再次被禁用。
代码:https://github.com/KaustubhMaladkar/Tip-Calculator
if (!peopleError && !billError) {
submit.removeAttribute("disabled");
}
if (billError || peopleError) submit.setAttribute("disabled", "")
答:
0赞
Kaustubh Maladkar
6/8/2022
#1
我要感谢@Nestoro对我的问题的评论,因为我的大部分(如果不是全部)回答都是基于他们的评论。
此代码将解决问题
if (!peopleError && !billError && Number(billElem.value) && Number(peopleElem.value)) submit.removeAttribute("disabled");
else submit.setAttribute("disabled", "");
评论