lint警告val()和text()被错误地调用(lint warning that val() and text() are called incorrectly)

编程入门 行业动态 更新时间:2024-10-25 06:30:17
lint警告val()和text()被错误地调用(lint warning that val() and text() are called incorrectly)

我有:

TotalPrice = parseInt(TotalPrice*100)/100; $('input[name=EstimatedPrice]').val(TotalPrice); $('#EstimatedPriceDisplay').text(TotalPrice);

而且我从lint得到了两个警告。

val()调用不正确

text()调用不正确。

通过执行以下操作,我能够消除错误调用的text()错误:

$('#EstimatedPriceDisplay').text('' + TotalPrice);

但这对我来说似乎有些愚蠢。

I have:

TotalPrice = parseInt(TotalPrice*100)/100; $('input[name=EstimatedPrice]').val(TotalPrice); $('#EstimatedPriceDisplay').text(TotalPrice);

and I'm getting two warnings from lint.

val() called incorrectly

text() called incorrectly.

I was able to eliminate the text() called incorrectly error by doing the following:

$('#EstimatedPriceDisplay').text('' + TotalPrice);

But that seems kinda kludgy to me.

最满意答案

你想支持IE <5.5吗? 如果没有,请尝试使用.toFixed()方法 ,该方法返回一个字符串并四舍五入到指定的小数位。

TotalPrice = TotalPrice.toFixed(2);

Do you want to support IE <5.5? If not, try to use the .toFixed() method, which returns a string and rounded to the specified decimal place.

TotalPrice = TotalPrice.toFixed(2);

更多推荐

本文发布于:2023-07-26 02:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269582.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   text   val   lint   called

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!