jQuery
jquery 숫자만
은둔한량
2013. 2. 18. 16:47
반응형
jQuery 숫자만 입력
1.input
<input type="text" name="name" class="numberic" style="ime-mode:disabled" />
2.javascript
$(document).ready(function(){
$('.numberic').keypress(function(e){
if(e.which && (e.which < 48 || e.which > 57) ) e.preventDefault();
});
$('.numberic').keyup(function(){
if( $(this).val() != null && $(this).val() != '' ) {
var tmps = parseInt($(this).val().replace(/[^0-9]/g, '')) || 0;
$(this).val(tmps);
}
});
});
반응형