【www.gdgbn.com--css3教程】





html5 网页特效 邮箱地址验证




 

    some bits about you
   

   
   
 


 

<script>
// default validation messages
var messages = {
  email: "be not a legal email address",
  url: "be not a valid web address",
  comment: "ye have to specify ye value"
};
var forms = document.getelementsbytagname("form"), i = forms.length, j, el;
while (i--) {
  j = forms[i].length;
  while (j--, el = forms[i][j]) {
    if (el.willvalidate && messages[el.name]) {
      el.setcustomvalidity(messages[el.name]);
    }
  }
}
</script>
<script>
var form = document.getelementsbytagname("form")[0];
form.onsubmit = function (event) {
  var i = this.length, el, cont = true, errors = [];
  while (i--, el = this[i]) {
    if (el.willvalidate) {
      if (!el.validity.valid) {
        errors.push("error with " + el.name + (el.validationmessage ? ": " + el.validationmessage: ""));
        cont = false;
      }
    }
  }
 
  if (errors.length) {
    // replace alert with your sexy css教程 info bubbles
    alert(errors.join("n"));
  }

  return cont;
};
</script>

本文来源:http://www.gdgbn.com/css/27948/