Function call inside jQuery plugin

I am creating my first jQuery plugin that automatically formats numbers in various international formats. Inside the plug-in there are a couple of functions that break lines and reformat the line, which should be called from another jQuery script.

Based on the structure of the plug-in below (let me know if you need all the code), can I call and send parameters to stripFormat(ii)and functions targetFormat(ii, iv)?

Or do I need to change my plug-in structure, and if so, how?

    (function($){
        var p = $.extend({
            aNum: '0123456789',
            aNeg: '-',
            aSep: ',',
            aDec: '.',
            aInput: '',
            cPos: 0
        });

        $.fn.extend({
             AutoFormat: function() {
                return this.each(function() {
                    $(this).keypress(function (e){
                        code here;
                    });

                    $(this).keyup(function (e){
                        code here;
                    });

                    // Would like to call this function from another jQuery script - see below.
                    function stripFormat(ii){
                        code here;
                    }

                    // Would like to call this function from another jQuery script - see below.
                    function targetFormat(ii, iv){
                        code here;
                    }

                });

            }
        });

    })(jQuery);

Ways to call plug-in functions:

    jQuery(function(){
            $("input").change(function (){ //temp function to demonstrate the stripFormat() function.
                document.getElementById(targetElementid).value = targetFormat(targetElementid, targetValue);
            });
    });

I tried to use these options without success:

    document.getElementById(targetElementid).value = $.targetFormat(targetElementid, targetValue);
    document.getElementById(targetElementid).value = $.autoFormat().targetFormat(targetElementid, targetValue);
+3
source share
1 answer

, , , : http://www.stilldesigning.com/dotstring/jquery.string.1.0.js

$.string(" <p>this is a test</p> ").strip().stripTags().capitalize().str
> 'This is a test'

, value options. , . http://plugins.jquery.com/project/currencyFormat

$('#some_element').currency() //will format the text of the element
$.currency(123456.78,{options}) //formats number and returns string

, document.getElementById("targetElement").value $("targetElement").val() $("targetElement").html()

-1

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


All Articles