解决方法
<input id="ssn"/> <script type="text/javascript"> $('#ssn').keyup(function() { var val = this.value.replace(/\D/g,''); var newVal = ''; while (val.length > 3) { newVal += val.substr(0,3) + '-'; val = val.substr(3); } newVal += val; this.value = newVal; }); </script>