javascript - 代码执行不起作用,因为代码不会导致框显示为红色
问题描述
执行方式 不确定是否在执行Java脚本
form.addEventListener('Submit', (e) => {
e.preventDefault():
checkInputs();
});
用于检查来自 html 文件的输入的函数
function checkInputs() {
// get the values form the inputs
const firstnameValue = first.value.trim();
const lastnameValue = second.value.trim();
const numberValue = phone.value.trim();
const amountValue = amount.value.trim();
必须满足的条件
if(firstnameValue === '') {
// show error
// add error class
setErrorFor(Forename, "Username is invlaid");
} else {
// add success class
setSucessFor(Forename);
}
}
不确定为什么该功能不起作用
function setErrorFor(input, message) {
const formControl = input.parentElement; // .form-control
const small = formControl.querySelector('small');
// add error message inside small
small.innerText = message;
// add errror class
formControl.className = 'form-control error';
}
解决方案
推荐阅读
- r - 由于奇点,未定义 glm 中的随机因子
- sql - 我有 3 列,总计数、通过计数和失败计数,如果失败计数 > 8% 其开发错误,我如何在 SQL 或 SPL 中编写公式
- python - 无法为形状为 (3, 1267618) 且数据类型为 float64 的数组分配 29.0 MiB
- c# - 如何在 C# 中调用方法?
- angular - 如何将 Hyperledger Fabric 智能合约链接到前端?
- laravel - Laravel Eloquent 方法中的连接表
- identityserver4 - 未设置对象引用 主视图中的错误 - MVC 客户端快速入门
- java - JavaSE-11 的无效运行时:路径指向丢失或无法访问的文件夹
- bash - Bash 如何在列表中的特定字符串匹配条件处开始迭代
- java - 为什么paintComponent方法会执行多次?