hdw
2018-12-06 417c6db1ab7698f625bcc6452c2936981fade14b
gx_tieta/WebRoot/js/whyc-jqueryui.js
@@ -484,12 +484,14 @@
   var TestVal = function(ele, options) {
      this.ele = ele;
      this.opts = options;
      this.ele.data('testVal', options);
   };
   var _proto = TestVal.prototype;
   
   // 根据数据的正确性修改文本框的样式
   _proto.changeVal = function() {
      var testVal = this;
      this.ele.off('input propertychange blur focus');
      
      // 文本框内容改变
      this.ele.on('input propertychange', function() {
@@ -515,9 +517,17 @@
         ele.myTooltip('hide');
         ele.removeClass('error-data');
         
         testVal.opts.btn.removeClass('whyc-btn-disabled');
         // 遍历testVal.opts.btn的值
         testVal.opts.btn.each(function() {
            if(!$(this).hasClass('error-data')) {
               $(this).removeClass('whyc-btn-disabled');
            }
            $(this).removeClass('error-data');
         });
      }else {
         ele.next('i').addClass('error-data');
         //console.log(testVal.opts.msg);
         ele.myTooltip({
                position: testVal.opts.position,
                thing: 'show',
@@ -525,6 +535,15 @@
                content: '<span style="color:#FF0000">'+testVal.opts.msg+'</span>'
         });
         ele.addClass('error-data');
         // 遍历testVal.opts.btn的值
         testVal.opts.btn.each(function() {
            if(!$(this).hasClass('whyc-btn-disabled') && !$(this).hasClass('error-data')) {
               $(this).addClass('whyc-btn-disabled');
            }else {
               $(this).addClass('whyc-btn-disabled error-data');
            }
         });
         
         testVal.opts.btn.addClass('whyc-btn-disabled');
      }
@@ -548,10 +567,11 @@
      
      return flag;
   };
   _proto.error = function() {
      console.info(this.opts.msg);
   };
   $.fn.testVal = function(options) {
   $.fn.testVal = function(options, attr, val) {
      var defaults = {
         pattern: "",
         event: "changeVal",
@@ -563,13 +583,29 @@
         max: 0,
         position: 'bottom'
      };
      var opts = $.extend(true, {}, defaults, options||{});
      var opts = {};
      // 判断是否为更新配置项
      if(isString(options)) {
         var oldOpts = this.data('testVal');
         opts = $.extend({}, opts, oldOpts);
         if(attr == 'allOpts') {
            opts = $.extend({}, opts, val);
         }else {
            opts[attr] = val;
         }
      }else if(isObject(options)){
         opts = $.extend(true, {}, defaults, options||{});
      }
      // console.log(opts);
      if(opts.pattern.constructor.name != 'RegExp') {
         opts.event = "error";
         opts.msg = '请输入正确的正则表达式格式!!!'
      }
      //console.log(opts);
      var testVal = new TestVal(this, opts);
      this.data('testVal', testVal.opts);
      testVal[opts.event]();
      
      return this;