表单验证

jquery方式:

<input type="text" name="student.id" notnull="true" title="编号">   //在不能为空的标签加上notnull="true"
....
<script type="text/javascript">
    (function(){
        $("").ready(function() {
            
            $("#fm1").submit(function(){
            
                var flag=true;
                $(this).find("[notnull=true]").each(function(){
                    
                    if(isnull(this)){
                        flag=false;
                    }
                    
                });
                return flag;
            });
            
            function isnull(oo){
                $(oo).next(".yz_1").remove();
                 if(oo.value=="")  {
                     $(oo).after("<span class='yz_1'> "+oo.title+"不能为空</span>");
                    // window.alert("blank");
                     return true;
                 }
                    
                 return false;
            }
        });
    })();
</script>

效果:

posted @ 2016-07-17 14:39  乱世_独自美  阅读(100)  评论(0)    收藏  举报