2017-03-16 92 views
-1

如何添加班级到数字“,”(逗号)1,00,000,000。我不想添加班级的所有数字。我只想添加类“,”。 有人可以帮我吗? 我使用此代码输出数字如果我输入数字100,000,000,如何在html中只添加逗号“,”?

<?php 
$re = "/([^\\s>])(?!(?:[^<>]*)?>)/u"; 
$str = $figure_one; 
$subst = "<span class='boxolor'>$1</span>"; 
$result = preg_replace($re, $subst, number_format($str)); 
?> 
<span class="price-text">£ </span> 
<a href="<?php echo $investment_link ; ?>"> 
    <span class="" data-value="<?php echo $result ; ?>"><?php echo $result ; ?></span> 
</a> 

我使用SMOF主题选项输出数字。我键入10000000,它给了我这样的结果1,00,000,000 我想改变“,”的颜色 我该怎么做?颜色应该只改变“,”不是数字。 预先感谢

+0

如果你在一个友好的方式格式化您的代码,你的问题会更具有可读性。 – Utkanos

回答

1
function numberWithCommas(x) { 
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "<span class='red'>,</span>"); 
} 

传递值以上的功能。

+0

感谢您的回复。我正在使用smof主题选项。我在文本字段中添加数字10000,前端应该是这样的http://prntscr.com/el4i0d我该如何做到这一点? –

2

不要让人很难简单地取代你的字符串

<?php 
    $str = "1,00,000,000"; 
    echo str_replace(",","<span class='red'>,</span>",$str); 
?> 

演示:https://eval.in/755705

0

请检查该代码。

function AddComma(txt) { 
 
     if (txt.value.length % 4 == 3) { 
 
      txt.value += ","; 
 
     } 
 
    }
<input onkeypress="AddComma(this)"/>

+0

感谢您的回复。我正在使用smof主题选项。我在文本字段中添加数字10000,前端应该是这样的http://prntscr.com/el4i0d我该如何做到这一点? –

相关问题