keypress is not working in Mozila Firefox

后端 未结 2 1057
有刺的猬
有刺的猬 2021-01-22 17:04

I have got a task to restrict textbox from alphabetic values. Only floating point values are possible. After the decimal we have to write out two digits. I did this but it does

2条回答
  •  一整个雨季
    2021-01-22 18:05

    function isNumberKey(evt) { 
         var charCode = (evt.charCode) ? evt.which : event.keyCode
    
         if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) 
             return false; 
         else { 
             var len = document.getElementById("txtChar").value.length; 
             var index = document.getElementById("txtChar").value.indexOf('.'); 
    
             if (index > 0 && charCode == 46) { 
                 return false; 
             } 
                 if (index >0 || index==0) { 
                     var CharAfterdot = (len + 1) - index; 
                     if (CharAfterdot > 3) { 
    
                         return false; 
                     } 
    
    }
    
             } 
             return true; 
          } 
    
    
    
    
    
    
    

提交回复
热议问题