日期:2014-05-16 浏览次数:20415 次
<script> //var a=/^(([0-9])|(1[0-2])|(2[0-3])):[0-5][0-9]$/ //alert(a.test("8:30")) //var a=/^(([0-9])|(1[0-2])|(2[0-3])):[0-5][0-9]$/ //alert(a.test("0:00")) //var a=/^(([0-9])|(1[0-2])|(2[0-3])):[0-5][0-9]$/ //alert(a.test("23:59")) //var b="123.4" //var c="123.4" function mm(m){ alert(m.replace(/^((\d+?)(\.?)(\d+?))$/,function (a,b,c,d,e){ if(d=="."){ return c+"."+e.substr(0,1)}else{ return b} })) } mm("123.4545") mm("123") </script>
------解决方案--------------------
<script>
var s="1,2,234,234.264234,1234.1234";
alert(s.replace(/(\.\d)\d+/ig,"$1") )//不要四舍五入的
alert(s.replace(/\d+\.\d+/ig,a))//要四舍五入的
function a(v){
return ((v*1).toFixed(1));
}
</script>