jQuery TimeAgo 插件 - 设置设置
我正在尝试“调整”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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
免责声明:我是 timeago 的作者。
不幸的是,正如 PetersenDidIt 指出的那样,timeago 目前不支持运行时选项。 GitHub 上有一个未解决的问题来解决这个问题,但我还没有时间研究它。 PetersenDidIt,感谢您的拉取请求。我会尽快看一下。
同时,这是几种可能的解决方法之一...
首先,默认情况下将后缀设置为空字符串:
接下来,像平常一样运行 timeago:
最后,不要添加“nosuffix”限定符,为每个需要后缀的时间戳添加一个类,并将后缀添加到所有这些时间戳一次:
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:
Next, run timeago like you normally would:
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:
只需将
suffixAgo
设置为空白字符串UPDATE
看起来该插件的当前版本不处理运行时选项。我创建了 git 存储库的一个分支,并创建了一个具有以下功能的版本:
https://github.com/petersendidit/jquery-timeago/blob/master/jquery.timeago.js
Just set
suffixAgo
to a blank stringUPDATE
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