我找到了网站所需的代码,但它并不是我想要的 ( 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/