H5约束验证API

1、willValidate属性  元素有没有被符合,没有的话返回false

2、validity 属性   willValidate的对象,验证状态

3、vaildationMessage属性 与元素相关的  失败信息

4、checkValidity()方法     元素是否满足任意约束  没有满足返回false  满足true

<form action="">
<input type="text" id="username" value="" required pattern="^\d{}">
</form>
<script>
var names = document.getElementById("username");
//补充完整!
if(names.checkValidity()){
document.write('true')
}else{
document.write('false')
}
</script

5、 setCustomValidity()方法   设置自定义的验证信息

猜你喜欢

转载自www.cnblogs.com/jian1234/p/9829620.html