2012-07-19 54 views
0

我使用下面的jQuery來對文本框進行十進制驗證。它在Internet Explorer和Chrome中很好地工作。如果我在FireFox中使用此項,BackSpace鍵在FireFox中不起作用。如何解決此問題?十進制驗證不適用於FireFox?

$('.decimalValidate').keypress(function(event) { 
         if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) { 
          event.preventDefault(); 
         } 
        }); 

回答

0

使用此鏈接檢查退格關鍵字。 http://www.javascripter.net/faq/keycodes.htm

希望這將解決您的問題在Mozilla中,但我不知道它將如何在其他瀏覽器中工作。

$('.decimalValidate').keypress(function(event) { 
    if (e.which===8) 
    { 
     return;           
    } 
    if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) { 
           event.preventDefault(); 
    } 
});