jQuery.fn.td_amountsof = function(options) { var defaults = { min: 0, max: 999, maxlen: 3, }; // rozszerzenie domyślnej konfiguracji var options = $.extend(defaults, options); var $this = $(this); if(!$this.val()) $this.val(0); $this.attr('maxlength',options.maxlen); $this.css({'width':options.maxlen*10, 'text-align': 'center'}); $this.prev().click(function() { if(options.min < parseInt($this.val())) $this.val(parseInt($this.val())-1); } ); $this.next().click(function() { if(options.max > parseInt($this.val())) $this.val(parseInt($this.val())+1); } ); }; $("input").td_amountsof(); <BODY> <INPUT Type="text" id="1"> <INPUT Type="text" id="2"> <INPUT Type="text" id="3"> <INPUT Type="text" id="4"> <INPUT Type="text" id="5"> <INPUT Type="text" id="6"> <INPUT Type="text" id="7"> <INPUT Type="text" id="8"> </BODY>
proszę o sugestie.
zauważyłem że plugin wykonuje się tylko raz dla pierwszego elementu, ale stosuje dla wszystkich, sprawdziłem to wstawiając alert($this).attr('id') - zwracało tylko raz "1". Myślałem że wykona się tyle razy ile jest inputów, przyznaję że nie rozumiem tego mechanizmu.