2011-12-21 16 views
0

javascriptのテンキーパッドにカンマ「、」を入れようとしています。以下のコードを参照してくださいJqueryテンキー入力問題

/*! 
* JQFNumKeypad 
* http://www.jqueryfun.com/ 
*/ 
(function($) { 
    $.fn.JQFNumKeypad = function(options) { 

    // Defaults 
    var defaults = { 
     fadeSpeed: 400, 
     clearText: 'Clear' 
    }; 

    // Extend options 
    var options = $.extend(defaults, options); 

    // Show keypad on document click/Focus First 
    $(document).click(function() {$('.jqfnumkeypad').show();}); 
    $(document).ready(function(){$('input').first().focus();}); 

    // Loop each instance 
    return this.each(function() { 

     // Instance 
     var instance = $(this); 

     // Keypad layout 
     var keypad = '<div id="jqfnumkeypad_' + instance.attr('name') + '" class="jqfnumkeypad"><div class="jqfnumkeypad_keypad"><table width="100%" cellpadding="0" cellspacing="0">'; 
     for(var i = 1; i <= 9; i++) { 
     if((i-1)%3 == 0) keypad += '<tr>'; 
     keypad += '<td class="jqfnumkeypad_digit">' + i + '</td>'; 
     if(i%3 == 0) keypad += '</tr>'; 
     } 
     keypad += '<tr><td class="jqfnumkeypad_digit">0</td><td class="jqfnumkeypad_clear">' + options.clearText + '</td><td class="jqfnumkeypad_coma">,</td></tr></table></div></div>'; 
     $(keypad).insertAfter(instance).css({right: 0, top: instance.position().top}); 

     // Prevent hide on click 
     instance.click(function(e) {e.stopPropagation();}); 

     // Define on focus event 
     instance.focus(function() { 
     $('#jqfnumkeypad_' + instance.attr('name')).css('z-index', '99').fadeIn(options.fadeSpeed, function() { 
      // Digit click 
      $('#jqfnumkeypad_' + instance.attr('name') + ' .jqfnumkeypad_digit').unbind().bind('click', function(e) { 
      if(instance.attr('maxlength') == -1 || instance.val().length < instance.attr('maxlength')) instance.val(instance.val() + parseFloat($(this).html())); 
      e.stopPropagation(); 
      }); 
      // Clear click 
      $('#jqfnumkeypad_' + instance.attr('name') + ' .jqfnumkeypad_clear').unbind().bind('click', function(e) { 
      instance.val(''); 
      e.stopPropagation(); 
      }); 
      // Coma click 
      $('#jqfnumkeypad_' + instance.attr('name') + ' .jqfnumkeypad_coma').unbind().bind('click', function(e) { 
      if(instance.attr('maxlength') == -1 || instance.val().length < instance.attr('maxlength')) instance.val(instance.val() + $(this).html()); 
      e.stopPropagation(); 
      }); 

     }).siblings('div').css('z-index', '0'); 
     // Blur to prevent instance events 
     instance.blur(); 
     }); 
    }); 
    } 
})(jQuery); 

問題を解決するお手伝いをしてもらえますか? 現在カンマボタンを押すと、入力フィールドがクリアされます。 http://digitalbush.com/projects/masked-input-plugin/

あなたのユーザーを持っている必要はありません。この方法は:必要な入力がオンになっているので、私はカンマが必要 は

+0

デバッグに関して何を試しましたか?コンマをクリックすると、それのクリックイベントハンドラが呼び出されますか? yesの場合、 'instance.attr( 'maxlength')'によって返される値は何ですか? – dgvid

答えて

0

なぜ入力フィールドにjQueryのためにマスクされた入力プラグインを使用していない欧州通貨形式を次の,を入力しても、希望のフォーマットが得られます。

関連する問題