如何在fmt中设置值:来自jquery函数的格式

时间:2013-09-11 11:27:07

标签: jquery jsp-tags

我需要从jquery中动态设置fmt:FormatNumber中的值。

<div id="total">
   <fmt:formatNumber value='${totalValue}' type="currency" maxFractionDigits="2"  minFractionDigits="2"/>
</div>

我试过这个

$('#total').find('fmt\\:formatNumber').attr('value', 'newValue');

这对我不起作用。你可以让我让我离开这个。

1 个答案:

答案 0 :(得分:1)

您正在将JSP标记与客户端脚本混合使用。当您致电<fmt:formatNumber />时,您要求服务器将文字文字打印到浏览器,例如$20,000.99,所以在您的源代码中看起来像:

<div id="total">&pound;20,000.00</div>

您可以将<fmt:formatNumber />包裹在一个范围内,例如

<强> JSP:

<div id="total">
   <span><fmt:formatNumber value='${totalValue}' type="currency" maxFractionDigits="2"  minFractionDigits="2"/></span>
</div>

<强> jQuery的:

$('#total').find('span').attr('value', 'newValue');

或者你可以使用现有的#total div:

$('#total').attr('value', 'newValue');