input 박스의 class 명으로 숫자 또는 숫자+dot 만 입력 받기 > 소스코드

본문 바로가기
사이트 내 전체검색


회원로그인

소스코드

jQuery | input 박스의 class 명으로 숫자 또는 숫자+dot 만 입력 받기

페이지 정보

작성자 100K5 작성일14-06-11 13:18 조회60,476회 댓글0건

본문

$(function(){
   //숫자키만 입력
   $(":input").filter(".only_number").keypress(function(event){  
       if (event.which && (event.which < 48 || event.which > 57)) {   
           event.preventDefault();
       }
   }) .css("imeMode", "disabled");
   // 또는
   $('.only_number').css('imeMode','disabled').keypress(function(event) {
    if(event.which && (event.which < 48 || event.which > 57) ) {
    event.preventDefault();
   }
   }).keyup(function() {
if( $(this).val() != null && $(this).val() != '' ) { 
$(this).val( $(this).val().replace(/[^0-9]/g, '') ); 
   }); 

   //숫자키와 dot 만 입력
   $(":input").filter(".only_number_dot").keypress(function(event){  
      if (event.which) {   
         if (event.which == 47 ) {
             event.preventDefault();
         }else{
            if (event.which < 46 || event.which > 57) {
               event.preventDefault();
            } 
         }
      }
    }) .css("imeMode", "disabled");
    // 또는
   $('.num_only2').css('imeMode','disabled').keypress(function(event) { 
if(event.which && (event.which < 48 || event.which > 57) ) { 
event.preventDefault(); 
   }).keyup(function() {
      if( $(this).val() != null && $(this).val() != '' ) { 
   var tmps = $(this).val().replace(/[^0-9]/g, ''); 
   var tmps2 = tmps.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
   $(this).val(tmps2);
    }); 
});

댓글목록

등록된 댓글이 없습니다.


사이트소개 개인정보취급방침 서비스이용약관 Copyright © kkujunhee.net All rights reserved.
상단으로

개인정보관리책임자 : 관리자

모바일 버전으로 보기