久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

JS自動給文本框的數字加千分位

 yanjj 2011-11-29

<head><title>Test</title></head>
<body>
   
<input type="text" id="input_box" value=""/>
   
<script>
       
var input_box = document.getElementById("input_box"),
            valueBuf,
            _valueBuf;
        input_box.onblur
=function(){
            valueBuf
=this.value;
            _valueBuf
= valueBuf.replace(/(\d{3})+$/g, function(){
               
var args = arguments,
                    len
= args.length,
                    ret
= args[0].match(/(\d{3})/g).join(',');
               
if(args[0] !== args[len -1]){
                    ret
=','+ ret;
                }
               
return ret;
            });
           
this.value = _valueBuf;
        }
       
        input_box.onfocus
=function(){
           
if(valueBuf){
               
this.value = valueBuf;
            }
        }
   
</script>
</body>
</html>

方法二:

<head><title>Test</title>
   
</head>
<body>
   
<input type="text" id="input_box" value=""/>
    <script>
       
var input_box = document.getElementById("input_box"),
            valueBuf;
        window.onload
=function(){
            input_box.value
='';
        }
        input_box.onblur
=function(){
            valueBuf
=this.value;
           
this.value = valueBuf.replace(/\d{3}(?=(?:\d{3})*$)/g, function(){
               
var args = arguments;
               
if(args[1] ===0){
                   
return args[0];
                }
else{
                   
return','+args[0];
                }
            });
        }
        input_box.onfocus
=function(){
           
if(valueBuf){
               
this.value = valueBuf;
            }
        }
   
</script>
</body>
</html>

方法三:

<head><title>Test</title></head>
<body>
   
<input type="text" id="input_box" value=""/>
   
<script>
       
var input_box = document.getElementById("input_box");
        input_box.onblur
=function(){
           
this.value =this.value.replace(/\d+?(?=(?:\d{3})+$)/g, function(s){
               
return s +',';
            });
        }
        input_box.onfocus
=function(){
           
this.value =this.value.replace(/,/g, '');
        }
   
</script>
</body>
</html>


    本站是提供個人知識管理的網絡存儲空間,,所有內容均由用戶發(fā)布,不代表本站觀點,。請注意甄別內容中的聯(lián)系方式,、誘導購買等信息,,謹防詐騙,。如發(fā)現有害或侵權內容,請點擊一鍵舉報,。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約