zoukankan      html  css  js  c++  java
  • easy ui 1.4的NumberBox,失去焦点后不能再次输入小数点

    这也是1.4版本的bug,现在1.4.1也发布了,经验证,该问题在新版本中已经解决了

    在网上找到的解决办法,地址:http://www.jeasyui.com/forum/index.php?topic=3659.msg8388

    在easy ui的js里,添加下面的js代码:

      1 /**
      2  * The Patch for jQuery EasyUI 1.4
      3  */
      4 (function($){
      5     var plugin = $.fn._size;
      6     $.fn._size = function(options, parent){
      7         if (typeof options != 'string'){
      8             return this.each(function(){
      9                 parent = parent || $(this).parent();
     10                 if (parent.length){
     11                     plugin.call($(this), options, parent);
     12                 }
     13             });
     14         } else if (options == 'unfit'){
     15             return this.each(function(){
     16                 var p = $(this).parent();
     17                 if (p.length){
     18                     plugin.call($(this), options, parent);
     19                 }
     20             });
     21         } else {
     22             return plugin.call(this, options, parent);
     23         }
     24     }
     25 })(jQuery);
     26 
     27 (function($){
     28     $.map(['validatebox','textbox','filebox','searchbox',
     29             'combo','combobox','combogrid','combotree',
     30             'datebox','datetimebox','numberbox',
     31             'spinner','numberspinner','timespinner','datetimespinner'], function(plugin){
     32         if ($.fn[plugin]){
     33             if ($.fn[plugin].defaults.events){
     34                 $.fn[plugin].defaults.events.click = function(e){
     35                     if (!$(e.data.target).is(':focus')){
     36                         $(e.data.target).trigger('focus');
     37                     }
     38                 };
     39             }
     40         }
     41     });
     42     $.fn.combogrid.defaults.height = 22;
     43     $(function(){
     44         $(document).bind('mousewheel', function(e){
     45             $(e.target).trigger('mousedown.combo');
     46         });
     47     });
     48 })(jQuery);
     49 
     50 (function($){
     51     function setMe(target){
     52         var state = $.data(target, 'textbox');
     53         var opts = state.options;
     54         state.textbox.find('.textbox-addon .textbox-icon').each(function(index){
     55             $(this).attr('tabindex', '-1');
     56         });
     57         $(target).textbox('textbox').unbind('focus.textbox').bind('focus.textbox', function(e){
     58             var tb = $(target).next();
     59             if (tb.hasClass('textbox-focused')){return;}
     60             if ($(this).val() != opts.value){
     61                 $(this).val(opts.value);
     62             }
     63             $(this).removeClass('textbox-prompt');
     64             tb.addClass('textbox-focused');
     65         });
     66     }
     67 
     68     var plugin = $.fn.textbox;
     69     $.fn.textbox = function(options, param){
     70         if (typeof options != 'string'){
     71             return this.each(function(){
     72                 plugin.call($(this), options, param);
     73                 setMe(this);
     74             });
     75         } else {
     76             return plugin.call(this, options, param);
     77         }
     78     };
     79     $.fn.textbox.methods = plugin.methods;
     80     $.fn.textbox.defaults = plugin.defaults;
     81     $.fn.textbox.parseOptions = plugin.parseOptions;
     82 })(jQuery);
     83 
     84 (function($){
     85     function setMe(target){
     86         var addon = $(target).next().find('.textbox-addon');
     87         addon.find('.spinner-arrow-up,.spinner-arrow-down').attr('tabindex','-1');
     88     }
     89 
     90     var plugin = $.fn.spinner;
     91     $.fn.spinner = function(options, param){
     92         if (typeof options != 'string'){
     93             return this.each(function(){
     94                 plugin.call($(this), options, param);
     95                 setMe(this);
     96             });
     97         } else {
     98             return plugin.call(this, options, param);
     99         }
    100     };
    101     $.fn.spinner.methods = plugin.methods;
    102     $.fn.spinner.defaults = plugin.defaults;
    103     $.fn.spinner.parseOptions = plugin.parseOptions;
    104 })(jQuery);
    105 
    106 (function($){
    107     $.extend($.fn.form.methods, {
    108         clear: function(jq){
    109             return jq.each(function(){
    110                 var target = this;
    111                 $('input,select,textarea', target).each(function(){
    112                     var t = this.type, tag = this.tagName.toLowerCase();
    113                     if (t == 'text' || t == 'hidden' || t == 'password' || tag == 'textarea'){
    114                         this.value = '';
    115                     } else if (t == 'file'){
    116                         var file = $(this);
    117                         if (!file.hasClass('textbox-value')){
    118                             var newfile = file.clone().val('');
    119                             newfile.insertAfter(file);
    120                             if (file.data('validatebox')){
    121                                 file.validatebox('destroy');
    122                                 newfile.validatebox();
    123                             } else {
    124                                 file.remove();
    125                             }
    126                         }
    127                     } else if (t == 'checkbox' || t == 'radio'){
    128                         this.checked = false;
    129                     } else if (tag == 'select'){
    130                         this.selectedIndex = -1;
    131                     }
    132                 });
    133                 
    134                 var t = $(target);
    135                 var plugins = ['textbox','combo','combobox','combotree','combogrid','slider'];
    136                 for(var i=0; i<plugins.length; i++){
    137                     var plugin = plugins[i];
    138                     var r = t.find('.'+plugin+'-f');
    139                     if (r.length && r[plugin]){
    140                         r[plugin]('clear');
    141                     }
    142                 }
    143                 $(target).form('validate');
    144             });
    145         }
    146     });
    147     $.extend($.fn.form.defaults, {
    148         onSubmit:function(){
    149             $(this).find('.textbox-text:focus').blur();
    150             return $(this).form('validate');
    151         }
    152     });
    153 })(jQuery);
    154 
    155 (function($){
    156     function setSize(target, param){
    157         var opts = $.data(target, 'linkbutton').options;
    158         if (param){
    159             $.extend(opts, param);
    160         }
    161         if (opts.width || opts.height || opts.fit){
    162             var btn = $(target);
    163             var parent = btn.parent();
    164             var isVisible = btn.is(':visible');
    165             if (!isVisible){
    166                 var spacer = $('<div style="display:none"></div>').insertBefore(target);
    167                 var style = {
    168                     position: btn.css('position'),
    169                     display: btn.css('display'),
    170                     left: btn.css('left')
    171                 };
    172                 btn.appendTo('body');
    173                 btn.css({
    174                     position:'absolute',
    175                     display:'inline-block',
    176                     left:-20000
    177                 });
    178             }
    179             btn._size(opts, parent);
    180             var left = btn.find('.l-btn-left');
    181             left.css('margin-top', 0);
    182             left.css('margin-top', parseInt((btn.height()-left.height())/2)+'px');
    183             if (!isVisible){
    184                 btn.insertAfter(spacer);
    185                 btn.css(style);
    186                 spacer.remove();
    187             }
    188         }
    189     }
    190 
    191     var plugin = $.fn.linkbutton;
    192     $.fn.linkbutton = function(options, param){
    193         if (typeof options != 'string'){
    194             return this.each(function(){
    195                 plugin.call($(this), options, param);
    196                 setSize(this);
    197             });
    198         } else {
    199             return plugin.call(this, options, param);
    200         }
    201     };
    202     $.fn.linkbutton.methods = plugin.methods;
    203     $.fn.linkbutton.defaults = plugin.defaults;
    204     $.fn.linkbutton.parseOptions = plugin.parseOptions;
    205     $.extend($.fn.linkbutton.methods, {
    206         resize: function(jq, param){
    207             return jq.each(function(){
    208                 setSize(this, param);
    209             })
    210         }
    211     })
    212 })(jQuery);
    213 
    214 (function($){
    215     var plugin = $.fn.dialog;
    216     $.fn.dialog = function(options, param){
    217         var result = plugin.call(this, options, param);
    218         if (typeof options != 'string'){
    219             this.each(function(){
    220                 var opts = $(this).panel('options');
    221                 if (isNaN(parseInt(opts.height))){
    222                     $(this).css('height', '');
    223                 }
    224                 var onResize = opts.onResize;
    225                 opts.onResize = function(w, h){
    226                     onResize.call(this, w, h);
    227                     if (isNaN(parseInt(opts.height))){
    228                         $(this).css('height', '');
    229                     }
    230                     var shadow = $.data(this, 'window').shadow;
    231                     if (shadow){
    232                         var cc = $(this).panel('panel');
    233                         shadow.css({
    234                              cc._outerWidth(),
    235                             height: cc._outerHeight()
    236                         });
    237                     }
    238                 }
    239                 if (opts.closed){
    240                     var pp = $(this).panel('panel');
    241                     pp.show();
    242                     $(this).panel('resize');
    243                     pp.hide();
    244                 }
    245             });
    246         }
    247         return result;
    248     };
    249     $.fn.dialog.methods = plugin.methods;
    250     $.fn.dialog.parseOptions = plugin.parseOptions;
    251     $.fn.dialog.defaults = plugin.defaults;
    252 })(jQuery);
    253 
    254 (function($){
    255     function createTab(container, pp, options) {
    256         var state = $.data(container, 'tabs');
    257         options = options || {};
    258         
    259         // create panel
    260         pp.panel({
    261             border: false,
    262             noheader: true,
    263             closed: true,
    264             doSize: false,
    265             iconCls: (options.icon ? options.icon : undefined)
    266         });
    267         
    268         var opts = pp.panel('options');
    269         $.extend(opts, options, {
    270             onLoad: function(){
    271                 if (options.onLoad){
    272                     options.onLoad.call(this, arguments);
    273                 }
    274                 state.options.onLoad.call(container, $(this));
    275             }
    276         });
    277         
    278         var tabs = $(container).children('div.tabs-header').find('ul.tabs');
    279         
    280         opts.tab = $('<li></li>').appendTo(tabs);    // set the tab object in panel options
    281         opts.tab.append(
    282                 '<a href="javascript:void(0)" class="tabs-inner">' +
    283                 '<span class="tabs-title"></span>' +
    284                 '<span class="tabs-icon"></span>' +
    285                 '</a>'
    286         );
    287         
    288         $(container).tabs('update', {
    289             tab: pp,
    290             options: opts
    291         });
    292     }
    293     function addTab(container, options) {
    294         var opts = $.data(container, 'tabs').options;
    295         var tabs = $.data(container, 'tabs').tabs;
    296         if (options.selected == undefined) options.selected = true;
    297         
    298         var pp = $('<div></div>').appendTo($(container).children('div.tabs-panels'));
    299         tabs.push(pp);
    300         createTab(container, pp, options);
    301         
    302         opts.onAdd.call(container, options.title, tabs.length-1);
    303         
    304         $(container).tabs('resize');
    305         if (options.selected){
    306             $(container).tabs('select', tabs.length-1);
    307         }
    308     }
    309     $.extend($.fn.tabs.methods, {
    310         add: function(jq, options){
    311             return jq.each(function(){
    312                 addTab(this, options);
    313             })
    314         }
    315     })
    316 })(jQuery);
    317 
    318 (function($){
    319     $.extend($.fn.menubutton.methods, {
    320         enable: function(jq){
    321             return jq.each(function(){
    322                 $(this).data('menubutton').options.disabled = false;
    323                 $(this).linkbutton('enable');
    324             });
    325         }
    326     });
    327 })(jQuery);
    328 
    329 (function($){
    330     var onAfterRender = $.fn.datagrid.defaults.view.onAfterRender;
    331     $.extend($.fn.datagrid.defaults.view, {
    332         updateRow: function(target, rowIndex, row){
    333             var opts = $.data(target, 'datagrid').options;
    334             var rows = $(target).datagrid('getRows');
    335             
    336             var oldStyle = _getRowStyle(rowIndex);
    337             $.extend(rows[rowIndex], row);
    338             var newStyle = _getRowStyle(rowIndex);
    339             var oldClassValue = oldStyle.c;
    340             var styleValue = newStyle.s;
    341             var classValue = 'datagrid-row ' + (rowIndex % 2 && opts.striped ? 'datagrid-row-alt ' : ' ') + newStyle.c;
    342             
    343             function _getRowStyle(rowIndex){
    344                 var css = opts.rowStyler ? opts.rowStyler.call(target, rowIndex, rows[rowIndex]) : '';
    345                 var classValue = '';
    346                 var styleValue = '';
    347                 if (typeof css == 'string'){
    348                     styleValue = css;
    349                 } else if (css){
    350                     classValue = css['class'] || '';
    351                     styleValue = css['style'] || '';
    352                 }
    353                 return {c:classValue, s:styleValue};
    354             }
    355             function _update(frozen){
    356                 var fields = $(target).datagrid('getColumnFields', frozen);
    357                 var tr = opts.finder.getTr(target, rowIndex, 'body', (frozen?1:2));
    358                 var checked = tr.find('div.datagrid-cell-check input[type=checkbox]').is(':checked');
    359                 tr.html(this.renderRow.call(this, target, fields, frozen, rowIndex, rows[rowIndex]));
    360                 tr.attr('style', styleValue).removeClass(oldClassValue).addClass(classValue);
    361                 if (checked){
    362                     tr.find('div.datagrid-cell-check input[type=checkbox]')._propAttr('checked', true);
    363                 }
    364             }
    365             
    366             _update.call(this, true);
    367             _update.call(this, false);
    368             $(target).datagrid('fixRowHeight', rowIndex);
    369         },
    370         onAfterRender: function(target){
    371             onAfterRender.call($.fn.datagrid.defaults.view, target);
    372             setTimeout(function(){
    373                 var opts = $(target).datagrid('options');
    374                 opts.pageNumber = opts.pageNumber || 1;
    375             },0);
    376         }
    377     });
    378     
    379     $.fn.datagrid.defaults.loader = function(param, success, error){
    380         var opts = $(this).datagrid('options');
    381         if (!opts.url) return false;
    382         if (opts.pagination && opts.pageNumber == 0){
    383             opts.pageNumber = 1;
    384             param.page = 1;
    385         }
    386         if (param.page == 0){
    387             return false;
    388         }
    389         $.ajax({
    390             type: opts.method,
    391             url: opts.url,
    392             data: param,
    393             dataType: 'json',
    394             success: function(data){
    395                 success(data);
    396             },
    397             error: function(){
    398                 error.apply(this, arguments);
    399             }
    400         });
    401     };
    402 })(jQuery);
    403 (function($){
    404     function indexOfArray(a,o){
    405         for(var i=0,len=a.length; i<len; i++){
    406             if (a[i] == o) return i;
    407         }
    408         return -1;
    409     }
    410     function endEdit(target, index){
    411         var state = $.data(target, 'datagrid');
    412         var opts = state.options;
    413         var updatedRows = state.updatedRows;
    414         var insertedRows = state.insertedRows;
    415         
    416         var tr = opts.finder.getTr(target, index);
    417         var row = opts.finder.getRow(target, index);
    418         if (!tr.hasClass('datagrid-row-editing')) {
    419             return;
    420         }
    421         
    422         if (!$(target).datagrid('validateRow', index)){return}
    423         
    424         var changed = false;
    425         var changes = {};
    426         tr.find('div.datagrid-editable').each(function(){
    427             var field = $(this).parent().attr('field');
    428             var ed = $.data(this, 'datagrid.editor');
    429             var t = $(ed.target);
    430             var input = t.data('textbox') ? t.textbox('textbox') : t;
    431             input.triggerHandler('blur');
    432             var value = ed.actions.getValue(ed.target);
    433             if (row[field] != value){
    434                 row[field] = value;
    435                 changed = true;
    436                 changes[field] = value;
    437             }
    438         });
    439         if (changed){
    440             if (indexOfArray(insertedRows, row) == -1){
    441                 if (indexOfArray(updatedRows, row) == -1){
    442                     updatedRows.push(row);
    443                 }
    444             }
    445         }
    446         opts.onEndEdit.call(target, index, row, changes);
    447         
    448         tr.removeClass('datagrid-row-editing');
    449         
    450         destroyEditor(target, index);
    451         $(target).datagrid('refreshRow', index);
    452         
    453         opts.onAfterEdit.call(target, index, row, changes);
    454     }
    455     function destroyEditor(target, index){
    456         var opts = $.data(target, 'datagrid').options;
    457         var tr = opts.finder.getTr(target, index);
    458         tr.children('td').each(function(){
    459             var cell = $(this).find('div.datagrid-editable');
    460             if (cell.length){
    461                 var ed = $.data(cell[0], 'datagrid.editor');
    462                 if (ed.actions.destroy) {
    463                     ed.actions.destroy(ed.target);
    464                 }
    465                 cell.html(ed.oldHtml);
    466                 $.removeData(cell[0], 'datagrid.editor');
    467                 
    468                 cell.removeClass('datagrid-editable');
    469                 cell.css('width','');
    470             }
    471         });
    472     }
    473     
    474     $.extend($.fn.datagrid.methods, {
    475         endEdit: function(jq, index){
    476             return jq.each(function(){
    477                 endEdit(this, index);
    478             })
    479         }
    480     })
    481 })(jQuery);
    482 
    483 (function($){
    484     function setGrid(target){
    485         var opts = $.data(target, 'propertygrid').options;
    486         $(target).datagrid('options').onBeforeEdit = function(index, row){
    487             if (opts.onBeforeEdit.call(target, index, row) == false){return false;}
    488             var dg = $(this);
    489             var col = dg.datagrid('getColumnOption', 'value');
    490             col.editor = row.editor;            
    491         }
    492     }
    493 
    494     var plugin = $.fn.propertygrid;
    495     $.fn.propertygrid = function(options, param){
    496         if (typeof options == 'string'){
    497             return plugin.call(this, options, param);
    498         } else {
    499             return this.each(function(){
    500                 plugin.call($(this), options, param);
    501                 setGrid(this);
    502             });
    503         }
    504     };
    505     $.fn.propertygrid.defaults = plugin.defaults;
    506     $.fn.propertygrid.methods = plugin.methods;
    507     $.fn.propertygrid.parseOptions = plugin.parseOptions;
    508 })(jQuery);
    509 
    510 (function($){
    511     $.fn.numberbox.defaults.filter = function(e){
    512         var opts = $(this).numberbox('options');
    513         var s = $(this).numberbox('getText');
    514         if (e.which == 45){    //-
    515             return (s.indexOf('-') == -1 ? true : false);
    516         }
    517         var c = String.fromCharCode(e.which);
    518         if (c == opts.decimalSeparator){
    519             return (s.indexOf(c) == -1 ? true : false);
    520         } else if (c == opts.groupSeparator){
    521             return true;
    522         } else if ((e.which >= 48 && e.which <= 57 && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8) {
    523             return true;
    524         } else if (e.ctrlKey == true && (e.which == 99 || e.which == 118)) {
    525             return true;
    526         } else {
    527             return false;
    528         }
    529     }
    530 })(jQuery);
    531 
    532 (function($){
    533     var FILE_INDEX = 0;
    534     function buildFileBox(target){
    535         var state = $.data(target, 'filebox');
    536         var opts = state.options;
    537         var id = 'filebox_file_id_' + (++FILE_INDEX);
    538         $(target).addClass('filebox-f').textbox($.extend({}, opts, {
    539             buttonText: opts.buttonText ? ('<label for="' + id + '">' + opts.buttonText + '</label>') : ''
    540         }));
    541         $(target).textbox('textbox').attr('readonly','readonly');
    542         state.filebox = $(target).next().addClass('filebox');
    543         state.filebox.find('.textbox-value').remove();
    544         opts.oldValue = "";
    545         var file = $('<input type="file" class="textbox-value">').appendTo(state.filebox);
    546         file.attr('id', id).attr('name', $(target).attr('textboxName')||'');
    547         file.css('visibility', 'visible');
    548         file.change(function(){
    549             $(target).filebox('setText', this.value);
    550             opts.onChange.call(target, this.value, opts.oldValue);
    551             opts.oldValue = this.value;
    552         });
    553         var btn = $(target).filebox('button');
    554         if (btn.length){
    555             if (btn.linkbutton('options').disabled){
    556                 file.attr('disabled', 'disabled');
    557             } else {
    558                 file.removeAttr('disabled');
    559             }            
    560         }
    561     }
    562 
    563     var plugin = $.fn.filebox;
    564     $.fn.filebox = function(options, param){
    565         if (typeof options != 'string'){
    566             return this.each(function(){
    567                 plugin.call($(this), options, param);
    568                 buildFileBox(this);
    569             });
    570         } else {
    571             return plugin.call(this, options, param);
    572         }
    573     };
    574     $.fn.filebox.methods = plugin.methods;
    575     $.fn.filebox.defaults = plugin.defaults;
    576     $.fn.filebox.parseOptions = plugin.parseOptions;
    577 })(jQuery);
    578 
    579 (function($){
    580     function forNodes(data, callback){
    581         var nodes = [];
    582         for(var i=0; i<data.length; i++){
    583             nodes.push(data[i]);
    584         }
    585         while(nodes.length){
    586             var node = nodes.shift();
    587             if (callback(node) == false){return;}
    588             if (node.children){
    589                 for(var i=node.children.length-1; i>=0; i--){
    590                     nodes.unshift(node.children[i]);
    591                 }
    592             }
    593         }
    594     }
    595     function findNodeBy(target, param, value){
    596         var data = $.data(target, 'tree').data;
    597         var result = null;
    598         forNodes(data, function(node){
    599             if (node[param] == value){
    600                 result = attachProperties(node);
    601                 return false;
    602             }
    603         });
    604         return result;
    605     }
    606     function getNode(target, nodeEl){
    607         return findNodeBy(target, 'domId', $(nodeEl).attr('id'));
    608     }
    609     function attachProperties(node){
    610         var d = $('#'+node.domId);
    611         node.target = d[0];
    612         node.checked = d.find('.tree-checkbox').hasClass('tree-checkbox1');
    613         return node;
    614     }
    615     $.fn.tree.methods.getChildren = function(jq, nodeEl){
    616         var target = jq[0];
    617         var nodes = [];
    618         var n = getNode(target, nodeEl);
    619         var data = n ? (n.children||[]) : $.data(target, 'tree').data;
    620         forNodes(data, function(node){
    621             nodes.push(attachProperties(node));
    622         });
    623         return nodes;
    624     }
    625 })(jQuery);
  • 相关阅读:
    metasploit--multi/samba/usermap_script
    msfcli 不能使用,在新版metasploit不再有效,推荐使用msfconsole
    test.fire渗透测试
    metasploit服务扫描与查点
    Synchronized底层实现
    正在使用的IDEA插件
    JavaWeb
    设计模式
    MySQL
    计算机网络
  • 原文地址:https://www.cnblogs.com/zzgblog/p/4087234.html
Copyright © 2011-2022 走看看