BootstrapValidator表单验证无法提交问题

用BootstrapValidator做表单验证遇见点击submit和未执行action的情况,看网上都是加个点击事件,然后$("id").submit(),既繁琐又不好用,几经查找发现BootstrapValidator验证有给提交按钮的属性: submitButtons: "提交按钮ID",下面贴出演示代码

1.html页面

<form action="#" method="post" role="form" id="myform">
    <div class="form-group">
        <label for="">label</label>
        <input type="text" class="form-control" id="text" name="username" placeholder="请输入姓名">
    </div>
    <button id="mytest" type="submit" class="btn btn-primary">Submit</button>
</form>

2.js页面

$("#myform).bootstrapValidator({
        live: 'enabled',//enabled是内容有变化就验证(默认),disabled和submitted是提交再验证
        excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件
        submitButtons: '#mytest',              //指定提交按钮
        message: '通用的验证失败消息',
        feedbackIcons: {                            //根据验证结果显示的各种图标
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            username: {
                validators: {
                    notEmpty: {                    //检测非空
                        message: '请输入内容'
                    },
                    stringLength: {                //检测长度
                        min: 6,
                        max: 30,
                        message: '长度必须在6-30之间'
                    }
                }
            }
        }
    });

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值