| | |
| | | // 根据数据的正确性修改文本框的样式
|
| | | _proto.changeVal = function() {
|
| | | var testVal = this;
|
| | | this.ele.off('input propertychange blur focus');
|
| | |
|
| | | // 文本框内容改变
|
| | | this.ele.on('input propertychange', function() {
|
| | |
| | | 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',
|
| | |
| | | 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');
|
| | | }
|
| | |
| | |
|
| | | 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",
|
| | |
| | | max: 0,
|
| | | position: 'bottom'
|
| | | };
|
| | | var opts = $.extend(true, {}, defaults, options||{});
|
| | | var opts = {};
|
| | | // 判断是否为更新配置项
|
| | | if(isString(options)) {
|
| | | var oldOpts = this.data('testVal');
|
| | | opts = $.extend({}, opts, oldOpts);
|
| | | 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 = '请输入正确的正则表达式格式!!!'
|
| | | }
|
| | |
|
| | | var testVal = new TestVal(this, opts);
|
| | | this.data('testVal', testVal.opts);
|
| | | |
| | | testVal[opts.event]();
|
| | |
|
| | | return this;
|