<!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 等属性也适用

相关文章:

  • 2021-06-12
  • 2021-10-05
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-19
  • 2022-12-23
  • 2021-07-08
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案