我想知道HTML5是否具有双重条目的表单验证(写入2个相同的密码),并且可以编写自己的异常?
Thanx提前!
解决方法
如果你想要一些更好的和HTML5的利用,请尝试:
http://www.html5rocks.com/en/tutorials/forms/html5forms/
http://www.html5rocks.com/en/tutorials/forms/html5forms/
<label>Password:</label> <input type="password" id="password" name="password"> <label>Confirm Password:</label> <input type="password" id="passwordconf" name="passwordconf" oninput="check(this)"> <script language='javascript' type='text/javascript'> function check(input) { if (input.value != document.getElementById('password').value) { input.setCustomValidity('The two passwords must match.'); } else { // input is valid -- reset the error message input.setCustomValidity(''); } } </script>
通过将它添加到您的CSS(下图)来使其变幻莫测.当HTML5验证失败时,它会在不利的输入字段周围放置一个红色的边框.
:invalid { border: 2px solid #ff0000; }
全做完了.您仍然应该使用alert()或服务器端验证来确保用户正确输入两个密码.不要依靠客户端任何东西.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。