zoukankan      html  css  js  c++  java
  • 表单验证

        <title></title>

        <script src="../../Content/js/jquery/jquery-2.1.1.min.js"></script>
        <script src="../../Content/js/bootstrap/bootstrap.js"></script>
        <link href="../../Content/js/bootstrap/bootstrap.min.css" rel="stylesheet" />
         <script type="text/javascript">
          
             (function (jQuery) {
                 $.extend({
                     Vaild: function (_this) {
                         if (!!$(_this).data("vaild")) {
                             var pattern = new RegExp($(_this).data("vaild"));
                             if (pattern.test($(_this).val())) {
                                 $(_this).parent().removeClass("has-error").addClass("has-success");
                                 $(_this).popover("destroy");
                             } else {
                                 $(_this).parent().addClass("has-error").removeClass("has-success");
                                 $(_this).data("toogle", "top").data("placement", "top").data("container", "body").data("content", $(_this).data("errmsg")).popover({ "trigger": "manual" }).popover("show");
                                 return false;
                             }
                         } else {
                             $(_this).parent().addClass("has-success");
                         }
                         return true;
                     }
                 });
                 $.fn.extend({
                     Vaild: function () {
                         $(this).each(function (index, _this) {
                             $(_this).submit(function () {
                                 var checkResult = true;
                                 for (var i = 0; i < _this.length; i++) {
                                     checkResult = $.Vaild(_this[i]) && checkResult;
                                 }
                                 return checkResult;
                             });
                             for (var i = 0; i < _this.length; i++) {
                                 $(_this[i]).blur(function () {
                                     $.Vaild(this);
                                 });
                             }
                         });
                     }
                 });
             })(jQuery);
             
        </script>
         <style>
         
            
            /*重构 popover */
            .popover
            {
                background: #C00;
                color: #FFF;
            }
            .popover .popover-content
            {
                padding: 1px 5px;
            }
            .popover.top > .arrow:after
            {
                border-top-color: #C00;
            }
            
            /*重构 bootstrap 默认错误提示 */
            .has-error input, .has-error textarea, .has-error select
            {
                background-color: #F2DEDE;
            }
            .has-success input, .has-success textarea, .has-success select
            {
                background-color: #DFF0D8;
            }
          
        </style>
    </head>
    <body>
        <!--prove-->


        <form style="padding:50px">
         <div class=" col-md-6"><input type="text" name="ARTICLE_TITLE" class="form-control"  placeholder="文章标题"data-vaild="^[u4e00-u9fa5]{2,15}$" data-errmsg="文章的标题应该是2-15字的中文"/></div>

      </form>

       
    </body>
        
         <script type="text/javascript">
            //prove初始化
            $("form").Vaild();
          </script>
    </html>

  • 相关阅读:
    Django的路由层 路由控制之有名分组
    Django的路由层 路由控制之简单配置
    django 静态文件配置
    基于Django实现的一个简单示例
    Java线程池Executor
    Java 多线程Thread
    Java 异常
    Elementary OS 使用fcitx安装搜狗词库、搜狗输入法(Ubuntu通用)
    Elementary OS常见软件(TIM、微信、企业微信)安装(二)
    dpkg 批量卸载
  • 原文地址:https://www.cnblogs.com/liuwenxu/p/7070974.html
Copyright © 2011-2022 走看看