jQuery Prettydate
The jQuery Prettydate plugin provides powerful validation for forms, making client-side form validation easier while offering a wealth of customization options to meet various application needs. The plugin bundles a set of useful validation methods, including URL and email validation, and provides an API for writing user-defined methods. All bundled methods use English as their default error messages, and have been translated into 37 other languages.
The current version of this plugin is 1.1.0.
Download jQuery Prettydate Validation Plugin.
Usage
To use the Prettydate plugin, you need to have an ISO8601 date in the title:
January 28th, 2008
January 27th, 2008
January 26th, 2008
Then apply the prettyDate method to them:
$(function() { $("a").prettyDate(); });
To localize the plugin, override the properties in $.prettyDate.messages. Here, German localization is used as an example:
$.prettyDate.messages = { now: "gerade eben", minute: "vor einer Minute", minutes: $.prettyDate.template("vor {0} Minuten"), hour: "vor einer Stunde", hours: $.prettyDate.template("vor {0} Stunden"), yesterday: "Gestern", days: $.prettyDate.template("vor {0} Tagen"), weeks: $.prettyDate.template("vor {0} Wochen") }
The plugin updates each selected element every 10 seconds. This way "just now" becomes "1 minute ago", then "x minutes ago", then "1 hour ago", and so on.
You can disable interval updates by setting the interval option to "false":
$(function() { $("a").prettyDate({ interval: false }); });
Or set a different time interval, for example: interval: 1000, to update each selected element every second:
$(function() { $("a").prettyDate({ interval: 1000 }); });
The value option reads the ISO8601 date string from the title attribute by default. Override this option to use another attribute, for example, a custom "isodate" attribute:
$(function() {
$("a").prettyDate({
function() { // "this" 是 DOM 元素
return $(this).attr("isodate");
}
});
});