formvalidation



<script>
    seajs.config({
        base: 'http://wanghj',
        alias: {
            '$': 'jquery/1.11.2/jquery-1.11.2.min.js',
            'jquery': 'jquery/1.11.2/jquery-1.11.2.min.js',
            'bootstrap': 'bootstrap/3.3.4/js/bootstrap.min.js',
            'formvalidation': 'formvalidation/0.6.0/formValidation.js',
            'formvalidation-bootstrap':'formvalidation/0.6.0/framework/bootstrap',
         }
    })
</script>



<form role="form" id="packForm" method="post">
    <div class="form-group">
         <label for="name">套餐名称</label>
          <input type="text" class="form-control" name="name" id="name" value="" laceholder="请输入套餐名称">
    </div>
</from>
 




<script>
seajs.use(['formvalidation'], function () {
     seajs.use(['formvalidation-bootstrap'], function () {
            var packForm = $("#packForm");
            packForm.formValidation({
                framework: 'bootstrap',
                err: {
                    container: 'popover'
                },
                icon: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields:{
                    name: {
                        validators: {
                            notEmpty: {
                                message: '套餐名称不能为空'
                            }
                        }
                    }
                }
            }).on('success.field.fv', function(e, data){

            }).on('err.field.fv', function(e, data) {

            }).on('success.form.fv', function(e){

                $.ajax({
                    url: '',
                    method: 'post',
                    dataType: 'json',
                    data: packForm.serialize()
                }).success(function(resp){

                    }
                }).fail(function(){

                });
            });


        })
    });//seajs.use
</script>

你可能感兴趣的:(jquery)