难道还没有任何浏览器支持HTML5的checkValidity()方法? [英] Do any browsers yet support HTML5's checkValidity() method?
问题描述
HTML5规范定义了一些非常有趣的验证组件,其中包括模式(用于验证对一个正则表达式)和需要(用于标记字段的要求的)。尽我所知道的,但是,没有浏览器还没有实际执行根据这些属性的验证。
The HTML5 spec defines some very interesting validation components, including pattern (for validating against a Regexp) and required (for marking a field as required). As best I can tell, however, no browser yet actually does any validation based on these attributes.
我发现跨引擎 HTML5支持比较,但没有有关验证有信息。在我尝试了浏览器(Firefox 3.5.8和Safari 4.0.4),没有对象有一个 checkValidity()
方法,所以我甚至无法运行验证虽然我可以定义他们。
I found a comparison of HTML5 support across engines, but there is no information about validation there. In the browsers I've tried (Firefox 3.5.8 and Safari 4.0.4), no object has a checkValidity()
method, so I can't run the validations even though I can define them.
是否有此功能的任何支持,在那里,所以我可以尝试?
Is there any support for this feature out there so I can experiment?
推荐答案
我测试了以下在谷歌浏览器:
I tested the following in Google Chrome:
<!DOCTYPE html>
<html>
<body>
<style>
.valid { color: #0d0; }
.invalid { color: #d00; }
</style>
<div id="output"></div>
<script>
function check(input) {
var out = document.getElementById('output');
if (input.validity) {
if (input.validity.valid === true) {
out.innerHTML = "<span class='valid'>" + input.id +
" is valid</span>";
} else {
out.innerHTML = "<span class='invalid'>" + input.id +
" is not valid</span>";
}
}
console.log(input.checkValidity());
};
</script>
<form id="testform" onsubmit="return false;">
<label>Required:
<input oninput="check(this)" id="required_input"
required />
</label><br>
<label>Pattern ([0-9][A-Z]{3}):
<input oninput="check(this)" id="pattern_input"
pattern="[0-9][A-Z]{3}"/>
</label><br>
<label>Min (4):
<input oninput="check(this)" id="min_input"
type=number min=4 />
</label><br>
</form>
</body>
</html>
Stangely,在&LT;组件&gt; .validity.valid
属性似乎正常工作,但调用&LT;组件&gt; .checkValidity()
总是返回true,所以它看起来像是一个尚未实现。
Stangely, the <element>.validity.valid
property seems to work correctly, but calling <element>.checkValidity()
always returns true, so it looks like that's not implemented yet.
这篇关于难道还没有任何浏览器支持HTML5的checkValidity()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!