将逗号添加到值

时间:2013-11-12 13:25:49

标签: jquery

我发现上一篇文章Add comma to numbers every three digits,但我似乎无法使其发挥作用。我找不到他在原帖中列出的格式编号,因此我使用了:http://code.google.com/p/jquery-numberformatter/

我也交换了他们的例子,但它不起作用:

$("#salary").blur(function(){
$(this).parseNumber({format:"#,###.00", locale:"us"});
$(this).formatNumber({format:"#,###.00", locale:"us"});
});

我想在我的所有“视图”值中添加逗号,我认为这就像我在下面做的那样简单。

<title>Current Server Stats - ~[date]&nbsp;&nbsp;&nbsp;&nbsp;~[time]</title>
~[wc:commonscripts]
<link href="/images/css/screen.css" rel="stylesheet" media="screen">
<link href="/images/css/print.css" rel="stylesheet" media="print">
<script src="/admin/ps/js/jquery.js"></script>
<script src="/admin/ps/js/jquery.numberformatter.js"></script>

    <script>
    $(document).ready(function() {
        $(".numbers").each(function() {
            $(this).format({format:"#,###", locale:"us"});
        });
    });
    </script>
</head>

然后:

<div class="box-round">

<table border="0" cellspacing="0" cellpadding="4">
<tr bgcolor="#f6f6f6">
<td class="bold">#</td>
<td class="bold">Date</td>
<td class="bold">App Node</td>
<td class="bold">Admin Views</td>
<td class="bold">Teacher Views</td>
<td class="bold">Parent Views</td>
<td class="bold">Student Views</td>
<td class="bold">Hits</td>
<td class="bold">PowerGrade Hits</td>
</tr>

~[tlist_sql;
SELECT
ag.date_value,
r.host_name,
ag.adminpvs,
ag.TeacherPVs,
ag.ParentPVs,
ag.StudentPVs,
ag.hits,
ag.PG3Hits
from aggstats ag
left outer join Server_Instance r on ag.Server_InstanceID = r.id
where date_value=to_date('~[date;dateformat='MM/DD/YYYY']','MM/DD/YYYY')
order by date_value ASC, r.host_name ASC;alternatecolor]
<tr bgcolor="#edf3fe">
<td>~(count;-)</td>
<td>~(ag.date_value;d)</td>
<td>~(r.host_name;t)</td>
<td class="numbers">~(ag.adminpvs;t)</td>
<td class="numbers">~(ag.teacherpvs;t)</td>
<td>~(ag.parentpvs;t)</td>
<td>~(ag.studentpvs;t)</td>
<td>~(ag.hits)</td>
<td>~(ag.PG3hits)</td>

</tr>
[/tlist_sql]
</table>
</div>

1 个答案:

答案 0 :(得分:2)

看起来像numberformatter在输入字段上工作或直接在数字上工作。但你是在td尝试它。 试试这个

$(document).ready(function() {
    $(".numbers").each(function() {
        var number=$(this).text();
        //alert(number);
        $(this).html($.formatNumber( number,{format:"#,###", locale:"us"}));
    });
});