解决方法
运行代码段来看它的工作
$('input.number').keyup(function(event) { // skip for arrow keys if(event.which >= 37 && event.which <= 40) return; // format number $(this).val(function(index,value) { return value .replace(/\D/g,"") .replace(/\B(?=(\d{3})+(?!\d))/g,",") ; }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <input class="number">