<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .active{
            color:red;
        }
    </style>
</head>
<body>
    <form action="s4.html" method="post" id="f1">
        <div>
            <input type="text">
        </div>
        <div>
            <input type="text">
        </div>
        <div>
            <input type="text">
        </div>
        <div>
            <input type="text">
        </div>
        <div>
            <input type="submit" value="提交">
        </div>
    </form>
<script src="../jquery-2.12.4.js"></script>
<script>
    $('#f1').find(':submit').click(function () {
        var tag = true;
        $('.active').remove();
        $('#f1').find(':text').each(function () {
            if($(this).val().length<=0){
                tag = false;
                span = document.createElement('span');
                span.innerText = '必填';
                $(span).addClass('active');
                $(this).after(span);
            }
        });
        return tag;
    })



</script>

</body>
</html>

 

posted on 2018-07-14 19:06  python我的最爱  阅读(267)  评论(0编辑  收藏  举报