Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

javascript - Do any browsers yet support HTML5's checkValidity() method?

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Sure. Opera and Chromium. But you can test yourself:

function supportsValidity(){
  var i = document.createElement('input');
  return typeof i.validity === 'object'
}

Here's a link to a sandbox where you can see Opera and Chrome in action: http://jsfiddle.net/vaZDn/light/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...