开发者

Changing date strings with jQuery and Regexp

Wh开发者_JAVA百科at kind of code should I use so that jQuery looks for every YYYY-MM-DD formatted (plain text) string on a page and it replaces it with DD-MM-YYYY?

Thanks a lot!


That might work:

$(document.body).contents().each(function(i,e) {
    $(e).text(function(i,text) {
        return text.replace(/(\d+)-(\d+)-(\d+)/g, function($full, $year, $month, $day) {
            return [$day, $month, $year].join('-');
        });
    });
});

Example: http://www.jsfiddle.net/Jm2UQ/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜