javascript - 从javascript生成的文本中删除点

标签 javascript jquery regex

我找到了网站所需的代码,但它并不是我想要的 ( change font size after decimal point ).

所以我有:

$.each($('.price'), function() {
  var price = $(this).html();
  $(this).html(price.replace(/(\D*)(\d*\.)(\d*)/, '<span style="font-size:16px;">$1</span><span style="font-size:22px;">$2</span><span style="font-size:14px;">$3</span>'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='price'>$ 270.30</div>
<div class='price'>eur 64.60</div>
<div class='price'>€ 290.12</div>
<div class='price'>dollars 240.50</div>

问题是我想要最后没有点的值,比如:$ 270 30

有什么想法吗?

最佳答案

The problem is that I want to have the value without the dot in the end, like: $ 270 30

然后从第二个捕获组中删除 \.。改变这个:

/(\D*)(\d*\.)(\d*)/

对此:

/(\D*)(\d*)\.(\d*)/

更新示例:

$.each($('.price'), function() {
  var price = $(this).html();
  $(this).html(price.replace(/(\D*)(\d*)\.(\d*)/, '<span style="font-size:16px;">$1</span><span style="font-size:22px;">$2</span> <span style="font-size:14px;">$3</span>'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='price'>$ 270.30</div>
<div class='price'>eur 64.60</div>
<div class='price'>€ 290.12</div>
<div class='price'>dollars 240.50</div>

关于javascript - 从javascript生成的文本中删除点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33712340/

相关文章:

php - 从客户端 DOM 序列化 SVG 的最佳方式是什么?

javascript - 无论如何将 Firebug 'profile' 结果记录到外部文件?

jquery - 集成 jQuery Cookie

regex - 有没有办法根据以前的捕获组匹配正则表达式,而不是以前捕获的?

java - 输入验证电话号码

javascript - 如何在 Angular 2 中获取 header 主体?

javascript - 为多级树的 d3-2way-tree 添加水平和垂直滚动条

jquery - 如何在 jQuery 中检索复选框值?

javascript - 将 setTimeout() 重置回最大时间而不执行?

javascript - 查找字符后的第一个字符串