<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>历史上的今天</title> <script src="jquery-1.8.3.min.js"></script> </head> <body> <script type="text/javascript"> var data = $.ajax({ dataType: "json", url: 'https://baike.baidu.com/cms/home/eventsOnHistory/06.json', success: function(result) { var hdori = result["06"]["0601"]; var hdorilen = hdori.length; var res = '好的,为您播报当天的历史。'; for (var index = hdorilen-1; index >= 0; index --){ var yearori = hdori[index].year; var yearstr = ''; if (parseInt(yearori) >= 0) { yearstr = yearori + '年'; }else{ yearstr = '公元前' + Math.abs(yearori) + '年'; } var title = hdori[index].title.replace(/<.*?>/ig,"").replace("\n",""); res += yearstr + title + '。'; } alert(res); } }); </script> </body> </html>
待续。。。