正则表达式判定保留2位小数的实现代码

废话不多说了,直接给大家贴代码了,具体代码如下所示:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery.min.js" ></script>
</head>
<body>
<li><a class="ba">6.88888888</a></li>
<script>
var b=$('.ba').html();
onload = function(){   
var a = b;
  var aNew;
  var re = /([0-9]+\.[0-9]{2})[0-9]*/;
  aNew = a.replace(re,"$1");
  $(".ba").html(aNew)
 } 
</script>
</body>
</html>

相关推荐