是否有浏览器还支持HTML5的checkValidity()方法?
是的,checkValidity()
在Google Chrome和Opera中也可以使用。这也很好-
示例
<!DOCTYPE html><html>
<body>
<style>
.valid {
color: #0B7866;
}
.invalid {
color: #0B6877;
}
</style>
<div id = "result"></div>
<script>
function check(input) {
var out = document.getElementById('result');
if (input.validity) {
if (input.validity.valid === true) {
out.innerHTML = "<span class='valid'>" + input.id +
" valid</span>";
} else {
out.innerHTML = "<span class='invalid'>" + input.id +
" not valid</span>";
}
}
console.log(input.checkValidity());
};
</script>
<form id = "testform" onsubmit = "return false;">
<label>Minimum:
<input oninput = "check(this)" id = "min_input"
type = number min=4 />
</label><br>
</form>
</body>
</html>
以上是 是否有浏览器还支持HTML5的checkValidity()方法? 的全部内容, 来源链接: utcz.com/z/334829.html