Creating jQuery plugins to automatically create page load numbering

I messed around with autoNumeric , a jQuery plugin that formats currency fields.

I would like to connect the plugin so that all currency fields are formatted by the time the user sees the page, for example, when loading.

Currently, by default, I can’t get by, because the fields are formatted when blurring, pressing keys, or other actions in the fields themselves.

I was experimenting with pluggable code, and it looks like it will take this relative newbie some time to solve this problem, if at all.

Anyone on this?

Lille

+3
source share
7

"focusout" . "change" (1.7.4).

$('input.money').autoNumeric({aNeg: '-'}).trigger('focusout'); 
+5

autoNumeric "onchange". , , , - . :

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

, !

+3

. , :

$('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));
    }   
});

});

+1

.

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');
    }
  });   
});

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));
        }

    }

     );
});
0

- 'update',

$(".input-numeric").autoNumeric('update');
0

2.* formatOnPageLoad, ​​ true.

, ;)

0

Source: https://habr.com/ru/post/1749033/


All Articles