js输⼊框错误提⽰代码代码如下(⼤佬勿喷):
input绑定onblur事件<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<style type="text/css">
div{ text-align: center; margin-top: 100px;}
input{ color: #000; outline: none;}
.span{ font-size: 14px; color: #999999; margin: 0 0 0 10px; user-select: none;}
.wrong{ color: red;}
.
right{ color: green;}
</style>
</head>
<body>
<div>
<input type="text" />
<span class="span">* 请输⼊6~16位密码</span>
</div>
<script>
// 1. 获取元素
var input = document.querySelector("input");
var span = document.querySelector("span");
// 2. 注册事件失去焦点
// 根据表单⾥⾯值得长度 input.value.length
if (this.value.length <6 || this.value.length >16){
span.innerHTML = "× 输⼊错误,请重新输⼊!";
span.className = "span wrong";
}else{
span.innerHTML = "√ 输⼊正确";
span.className = "span right";
}
}
</script>
</body>
</html>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。