Home >Web Front-end >H5 Tutorial >The required attribute of the input element is invalid

The required attribute of the input element is invalid

高洛峰
高洛峰Original
2017-02-09 14:55:445224browse

Safari does not support the required attribute of input, which can be solved with js

$(document).ready(function(){
    $("form").submit(function(e) {
        var ref = $(this).find("[required=required]");
        alert('ref');
        $(ref).each(function(){
            if ( $(this).val() == '' )
            {
                alert("Required field should not be blank.");
                $(this).focus();
                e.preventDefault();
                return false;
            }
        });  return true;
    });
});

For more related articles about the invalid required attribute of input elements, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn