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/
精彩评论