js光標

jquery.formatCurrency-1.4.0.js 

$scope.replaceChar=function (id,index)

{
var elm= $('#'+id+index)[0];
            
            var postion = 0;
//get cusor postion
if(elm.createTextRange)
{   // IE                
       var range = document.selection.createRange();                  
       range.setEndPoint('StartToStart', elm.createTextRange());                  
       postion = range.text.length;   
   } 
   else if(typeof elm.selectionStart == 'number')
   {   // Firefox  chrome 
       postion = elm.selectionStart;   
   }   
          
$('#'+id+index).val($('#'+id+index).val().replace(/[^0-9.]/g,''));  


if(postion != 0)
{
if(elm.createTextRange)
{   // IE   
       var textRange = elm.createTextRange();   
       textRange.moveStart('character', postion);               
       textRange.collapse();          
       textRange.select();        
   }else if(elm.setSelectionRange) 
   {   // Firefox  chrome 
       elm.setSelectionRange(postion, postion);   
       elm.focus();   
   } 


}   

}



 $scope.formatNumber=function (id,index,type)
{
if(type==0)
{
$('#'+id+index).formatCurrency();
}else
{
var elm= $('#'+id+index)[0];
            
           var postion = 0;
//get cusor postion
if(elm.createTextRange)
{   // IE                
       var range = document.selection.createRange();                  
       range.setEndPoint('StartToStart', elm.createTextRange());                  
       postion = range.text.length;   
   } 
   else if(typeof elm.selectionStart == 'number')
   {   // Firefox  chrome 
       postion = elm.selectionStart;   
   }   


   if(postion>0)
   {
    var splitcount = $('#'+id+index).val().substring(0,postion).split(',');
    if(postion>(splitcount-1))
    {
    var shifttemp = splitcount-1;
    postion = postion-shifttemp;
    }
   }


$('#'+id+index).toNumber();


if(postion != 0)
{
if(elm.createTextRange)
{   // IE   
       var textRange = elm.createTextRange();   
       textRange.moveStart('character', postion);               
       textRange.collapse();          
       textRange.select();        
   }else if(elm.setSelectionRange) 
   {   // Firefox  chrome 
       elm.setSelectionRange(postion, postion);   
       elm.focus();   
   } 
}   
}
 
}



數字輸入限制一句話

onKeyPress="if(event.keyCode < 45 || event.keyCode > 57 ) event.returnValue = false;"



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章