在<script>中:

$(function(){
  var num=$(".price").length;/*获取应用了class="price"的标签数量*/
  for(var i=0;i<num;i++){
    if($(".price")[i].innerText!="")
      $(".price")[i].innerText=parseInt($(".price")[i].innerText).toFixed(2);/*要先将文本值转换为int型,再格式化*/
  }
});

在网页中:

<span class="price">200</span>

<span class="price">400.9</span>

<span class="price">200.3897</span>

 

相关文章:

  • 2021-10-04
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-02-10
相关资源
相似解决方案