jquery两个替换函数



我不确定为什么在这个小提琴示例中没有删除项目计数括号。

编辑:这是我查看工作答案的结果。

$.fn.itemcount = function(){
     var text = $(this).text();
     text = text.replace("(","").replace(")","");
     $(this).text(text);
};
$("#prc").itemcount();
$.fn.sidecartcost = function(){
  var el = $(this);
  var text = $(this).text();
  text = text.replace("Your sub total is", "").replace(". ", "");
  $(this).text(text);
};
$('.SideCartCost').sidecartcost();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="prc">(7 Items)</div>
<div class="blank">Woo</div>
<div class="SideCartCost">Your sub total is $300.03. </div>

你不会像这样替换div的html/文本 http://jsfiddle.net/x5jeL/1/

最新更新