我想要 jquery timeago 只显示几天前的时间!我的意思是,经过 30 天后,它会显示 31,32,32 天,而不是 1 个月。感谢您的及时答复。

有帮助吗?

解决方案

一种解决方案是修改插件以获得您所描述的行为。考虑第 83 行 jquery.timeago.js:

days < 30 && substitute($l.days, Math.round(days)) ||

举个例子,如果你改变 3040, ,像这样:

days < 40 && substitute($l.days, Math.round(days)) ||

该插件仍会显示“x 天前”,直到 39 天前。

如果您想完全禁用大于“天”的单位,您可以在分配中取出该部分 words, ,像这样:

var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
            seconds < 90 && substitute($l.minute, 1) ||
            minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
            minutes < 90 && substitute($l.hour, 1) ||
            hours < 24 && substitute($l.hours, Math.round(hours)) ||
            hours < 42 && substitute($l.day, 1) ||
            substitute($l.days, Math.round(days));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top