javascript - Bootstrap 表单验证
阿神
阿神 2017-04-10 16:35:32
[JavaScript讨论组]

修改了wecenter花哨的表单验证提示后如下

          

现在的问题是任意项报错has-error再修正后依然无法改变状态,也就是表单失去焦点不重新验证添加has-success,其中if ($(this).attr('tips') != '') {这if貌似多于,求修正方法,先谢过!

简单的说假如首次输入名字不符合规则表单class添加has-error警示,用户修改正解后依然不改变表单红色边框!

源码

                
  •     verify_register_form('#register_form');
    
        /* 注册页面验证 */
        function verify_register_form(element)
        {
            $(element).find('[type=text], [type=password]').on({
                focus : function()
                {
                    if (typeof $(this).attr('tips') != 'undefined' && $(this).attr('tips') != '')
                    {
                        $(this).parent().append('' + $(this).attr('tips') + '');
                    }
                },
                blur : function()
                {
                    if ($(this).attr('tips') != '')
                    {
                        switch ($(this).attr('name'))
                        {
                            case 'user_name' :
                                var _this = $(this);
                                $(this).parent().find('.aw-reg-tips').detach();
                                if ($(this).val().length >= 0 && $(this).val().length < 2)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('' + $(this).attr('errortips') + '');
                                    return;
                                }
                                if ($(this).val().length > 17)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('' + $(this).attr('errortips') + '');
                                    return;
                                }
                                else
                                {
                                    $.post(G_BASE_URL + '/account/ajax/check_username/', 
                                        {
                                            username: $(this).val()
                                        }, function (result)
                                    {
                                        if (result.errno == -1)
                                        {
                                            _this.parent().find('.aw-reg-tips').detach();
                                            _this.parent().append('' + result.err + '');
                                        }
                                        else
                                        {
                                            _this.parent().find('.aw-reg-tips').detach();
                                            _this.parent().append('');
                                        }
                                    }, 'json');
                                }
                                return;
    
                        }
                    }
    
                }
            });
        }
    阿神
    阿神

    闭关修行中......

    全部回复(1)
    PHP中文网

    自己琢磨.removeClass('has-error') 搞掂。

    热门教程
    更多>
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送
    PHP中文网APP
    随时随地碎片化学习

    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号