Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 仅在第一条规则确定后显示规则中的更改_Javascript_Html_Css - Fatal编程技术网

Javascript 仅在第一条规则确定后显示规则中的更改

Javascript 仅在第一条规则确定后显示规则中的更改,javascript,html,css,Javascript,Html,Css,let reg=/[A-Z]/; document.querySelector(“.password\uu input”).addEventListener(“input”,function()){ if(document.querySelector(“.password\u input”).value.length

let reg=/[A-Z]/;
document.querySelector(“.password\uu input”).addEventListener(“input”,function()){
if(document.querySelector(“.password\u input”).value.length<10){
document.querySelector(“.rule\u length”).style.color=“red”;
}else if(注册测试(document.querySelector(“.password\uu input”)。值==false)){
document.querySelector(“.rule\u capital”).style.color=“红色”;
}
});

Пароль

密码应该有
  • 至少10个符号
  • 大写字母

您的代码中有一些错误,例如
else if(reg.test(document.querySelector(“.password\uu input”)。value==false))
如果(reg.test(document.querySelector(“.password\uu input”).value)==false)
document.querySelector(“.password\uu input”).addEventListener(“input”,function(){
没有像
input
这样的事件,我已经用
keyup
事件修复了您的代码,希望它能有所帮助

let reg=/[A-Z]/;
让pInput=document.querySelector(“.password\uu input”);
让ruleLength=document.querySelector(“.rule_u_长度”);
设ruleCapital=document.querySelector(“.rule_u大写”);
addEventListener(“keyup”,function()){
if(pInput.value.length<10){
ruleLength.style.color=“红色”;
ruleCapital.style.color=“红色”;
}否则{
ruleLength.style.color=“绿色”;
如果(!注册测试(输入值)){
ruleCapital.style.color=“红色”;
}否则{
ruleCapital.style.color=“绿色”;
}
}
});

Пароль

密码应该有
  • 至少10个符号
  • 大写字母

您好,谢谢您的更正!不幸的是,在这种情况下,规则也会立即更改颜色,但我需要他们等到第一条规则正确后才开始更改颜色。有可能吗?@MikeL。我认为这个答案可以做到这一点,您应该接受!