3

我一直在搞乱autoNumeric,这是一个用于格式化货币字段的 jQuery 插件。

我想连接插件,以便在用户看到页面时(例如加载时)对所有货币字段进行格式化。

目前,我似乎无法解决的默认设置是字段根据字段本身的模糊、键或其他操作进行格式化。

我一直在试验插件代码,看起来这个相对较新的人需要一些时间来解决这个问题,如果有的话。

有人在这吗?

里尔

4

7 回答 7

5

触发 'focusout' 事件会格式化该字段。触发“更改”在最新版本 (1.7.4) 中不起作用。

$('input.money').autoNumeric({aNeg: '-'}).trigger('focusout'); 
于 2012-04-10T09:13:20.637 回答
3

autoNumeric 在 'onchange' 事件触发后进行所有格式化。因此,您只需要以编程方式触发此事件。像这样:

$('input.money').autoNumeric({aNeg: '-'}).trigger('change');

希望这可以帮助!

于 2010-08-24T09:21:40.853 回答
1

我自己也遇到了这个问题。我必须使它更通用,但这对我有用:

$('input.auto-numeric').ready(function(){
var format_options = {
    aSign: '$'  
};
$('input.auto-numeric').each(function(){
    $(this).autoNumeric(format_options);
    if($(this).attr('id')){
        $(this).val($.fn.autoNumeric.Format($(this).attr('id'), $(this).val(), format_options));
    }   
});

});

于 2010-06-16T22:17:13.067 回答
0

这就是我最终所做的:

$(document).ready(function(){

$('input.auto').autoNumeric();

    $('input.auto').each(function(){
    var element = this
    if(element.value !=""){
        $('#'+element.id).val($.fn.autoNumeric.Format(element.id, element.value));
        }

    }

     );
});
于 2010-08-30T13:07:20.473 回答
0

这应该有效。

jQuery(function($) {
$('input.auto').ready(function(){
    $('input.auto').autoNumeric();
    var inputID = uniqueID; // use the jQuery.get() function to retrieve data
    var formatValue = '1234.00'; // use the jQuery.get() function to retrieve data
    if(jQuery().autoNumeric){
        $('#id').val($.fn.autoNumeric.Format(inputID, formatValue));
    }
    else{
     alert('plugin not available');
    }
  });   
});

鲍勃

于 2010-06-12T11:00:15.110 回答
0

强制格式化的另一种方法是使用“更新”,例如

$(".input-numeric").autoNumeric('update');
于 2016-12-14T23:08:51.677 回答
0

在当前版本2.*及以后的版本中,由于formatOnPageLoad设置为true.

就这么简单;)

于 2017-07-20T06:17:33.490 回答