jQuery Prettydate

The jQuery Prettydate plugin provides powerful validation functionality for forms, making client-side form validation simpler, while also providing a large number of customization options to meet various application requirements. The plugin bundles a useful set of validation methods, including URL and email validation, and also provides an API for writing user-defined methods. All bundled methods use English as the default error message and have been translated into 37 other languages.

The current version of this plugin is 1.1.0.

DownloadjQuery Prettydate Validation (Password Validation) plugin。

Usage

To use the Prettydate plugin, you need to include an ISO8601 date in the title:

<a title="2008-01-28T20:24:17Z">January 28th, 2008</a> 
<a title="2008-01-27T22:24:17Z">January 27th, 2008</a> 
<a title="2008-01-26T22:24:17Z">January 26th, 2008</a>

Then apply the prettyDate method to them:

$(function() { $("a").prettyDate(); });

To localize this plugin, override the properties in $.prettyDate.messages. Here, taking German localization 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") }

This plugin updates each selected element every 10 seconds. In this way, "just now" will change to "1 minute ago", then to "x minutes ago", then to "1 hour ago", and so on.

You can disable interval updates by specifying the interval option as "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 other attributes, for example, a custom "isodate" attribute:

$(function() { 
    $("a").prettyDate({
        function() { // "this" 是 DOM 元素
            return $(this).attr("isodate");
        } 
    }); 
});
Other Extensions