jQuery TimeAgo 插件 - 设置设置

发布于 2024-10-01 01:30:57 字数 468 浏览 2 评论 0原文

我正在尝试“调整”TimeAgo 插件,以便我可以根据具体情况删除后缀“ago”。

这是我尝试过的方法

$("time.timeago-nosuffix").timeago({suffixAgo: ""});

$("time.timeago-nosuffix").timeago({ settings: { strings: { suffixAgo: null}} });

$(document).ready(function () {
    $("time.timeago").timeago();
    $("time.timeago-nosuffix").timeago(function () {
        suffixAgo: "" 
    });
});

没有任何运气。

I'm trying to "tweek" the TimeAgo plugin so that I can remove the suffix "ago" on a case by case basis.

Here's what I've tried

$("time.timeago-nosuffix").timeago({suffixAgo: ""});

and

$("time.timeago-nosuffix").timeago({ settings: { strings: { suffixAgo: null}} });

as well as

$(document).ready(function () {
    $("time.timeago").timeago();
    $("time.timeago-nosuffix").timeago(function () {
        suffixAgo: "" 
    });
});

with out any luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

攒一口袋星星 2024-10-08 01:30:57

免责声明:我是 timeago 的作者。

不幸的是,正如 PetersenDidIt 指出的那样,timeago 目前不支持运行时选项。 GitHub 上有一个未解决的问题来解决这个问题,但我还没有时间研究它。 PetersenDidIt,感谢您的拉取请求。我会尽快看一下。

同时,这是几种可能的解决方法之一...

首先,默认情况下将后缀设置为空字符串:

$.timeago.settings.strings.suffixAgo = "";

接下来,像平常一样运行 timeago:

$("time.timeago").timeago()

最后,不要添加“nosuffix”限定符,为每个需要后缀的时间戳添加一个类,并将后缀添加到所有这些时间戳一次:

$("time.timeago.suffix").after(" ago")

Disclaimer: I'm the author of timeago.

Unfortunately, as PetersenDidIt pointed out, timeago doesn't currently support runtime options. There's been an open issue on GitHub to address this, but I haven't had the time to look into it. PetersenDidIt, Thanks for the pull-request. I'll take a look as soon as I can.

Meanwhile, here's one of several possible workarounds...

First, set the suffix to an empty string by default:

$.timeago.settings.strings.suffixAgo = "";

Next, run timeago like you normally would:

$("time.timeago").timeago()

Lastly, instead of adding a "nosuffix" qualifier, add a class to each timestamp for which you want a suffix and add the suffix to all of those timestamps once:

$("time.timeago.suffix").after(" ago")
动听の歌 2024-10-08 01:30:57

只需将 suffixAgo 设置为空白字符串

$("time.timeago-nosuffix").timeago({strings: {suffixAgo: ""}});

UPDATE
看起来该插件的当前版本不处理运行时选项。我创建了 git 存储库的一个分支,并创建了一个具有以下功能的版本:

https://github.com/petersendidit/jquery-timeago/blob/master/jquery.timeago.js

Just set suffixAgo to a blank string

$("time.timeago-nosuffix").timeago({strings: {suffixAgo: ""}});

UPDATE
Looks like the current version of the plugin doesn't handle runtime options. I created a fork of the git repository and created a version that does:

https://github.com/petersendidit/jquery-timeago/blob/master/jquery.timeago.js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文