浏览代码

added setvalue function which triggers formatting when setting a value programatically
$(selector).inputmask('setvalue', '23031973');

Robin Herbots 15 年之前
父节点
当前提交
f0a9f2f92f
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      jquery.inputmask.js

+ 12 - 2
jquery.inputmask.js

@@ -3,7 +3,7 @@ Input Mask plugin for jquery
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 Robin Herbots
 Copyright (c) 2010 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 0.0.5
+Version: 0.0.6
    
    
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 */
 */
@@ -73,7 +73,10 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                 });
                 });
             } else if (fn == 'unmaskedvalue') {
             } else if (fn == 'unmaskedvalue') {
                 return unmaskedvalue($(this));
                 return unmaskedvalue($(this));
-            } else { //maybe fn is a mask so we try
+            } else if (fn == 'setvalue') {
+                return setvalue($(this), options);
+            } 
+            else { //maybe fn is a mask so we try
                 //set mask
                 //set mask
                 opts.mask = fn;
                 opts.mask = fn;
 
 
@@ -150,6 +153,13 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
             }
             }
         }
         }
 
 
+		function setvalue(el, value) {
+		    var pasteEventName = $.browser.msie ? 'paste' : 'input';
+            el.val(value).trigger(pasteEventName);
+            el.blur();
+            return el;
+        }
+
         function mask(el) {
         function mask(el) {
             var input = $(el);
             var input = $(el);
             //store tests in the input element - used to get the unmasked value
             //store tests in the input element - used to get the unmasked value