码迷,mamicode.com
首页 > 其他好文 > 详细

input 的各种属性的验证 checkValidity兼容性

时间:2017-11-22 13:02:09      阅读:1715      评论:0      收藏:0      [点我收藏+]

标签:ie10   mail   htm   ret   char   兼容   false   oct   als   

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title></title>
</head>

<body>
    <form onsubmit="testform()" novalidate="true">
        <label for="email"> 邮箱:</label>
        <input type="email" id="email" name="email" />
        <input type="submit" value="提交">
    </form>
</body>


<script>
    function testform() {
        var email = document.getElementById(email);
        if (email.value == ‘‘) {
            alert(请输入email!);
            return false;
        } else if (!email.checkValidity()) {
            alert(email的格式不正确!);
            return false;
        }
    }
</script>

</html>

兼容到IE10及以上

required 等属性也适用

input 的各种属性的验证 checkValidity兼容性

标签:ie10   mail   htm   ret   char   兼容   false   oct   als   

原文地址:http://www.cnblogs.com/moxiaowohuwei/p/7878442.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!