:
Implementation Code:
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
</Head>
<Body>
<Table id = 'tbl1' cellpadding = "1" cellspacing = "1" bgcolor = "#333333" width = "800px" style = "line-height: 30px;">
<Tr bgcolor = "# FFFFFF"> <td align = "center" width = "70%"> title </td> <td align = "center" width = "30%"> time </td> </tr>
</Table>
<Div id = "loading" style = "display: none"> <font color = 'red'> loading data... </Font> </div>
</Body>
</Html>
<Script language = "javascript" type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>
<Script language = "javascript" type = "text/javascript">
$ (Function (){
Var html = "";
Var bgcolor = "";
$. Ajax ({
Url: "http://www.cnblogs.com/rss ",
Type: "get ",
// DataType :( $. browser. msie )? "Text": "xml ",
Success: function (data ){
$ ("Item", data). each (function (index, element ){
Bgcolor = index % 2 = 0? "Bgcolor = '# F1F1F1'": "bgcolor = '# ffff '";
Html + = "<tr" + bgcolor + "> <td> <a href = '" + $ (this ). find ("link "). text () + "'>" + FormatContent ($ (this ). find ("title "). text (), 40) + "</td> <td>" + new Date ($ (this ). find ("pubDate "). text ()). format ("yyyy-MM-dd hh: mm: ss"); + "</td> </tr> ";
});
$ ("# Tbl1 tr: not (': first')"). remove (); // remove non-first row
$ ("# Tbl1"). append (html); // bind data to table
},
Complete: function (){
$ ("# Loading"). hide ();
},
BeforeSend: function (x ){
// X. setRequestHeader ("Content-Type", "charset = UTF-8 ");
$ ("# Loading"). show ();
},
Error: function (){
Alert ("error ");
}
});
});
</Script>
<Script language = "javascript">
/**
* Format the time object;
*/
Date. prototype. format = function (format ){
/*
* Eg: format = "YYYY-MM-dd hh: mm: ss ";
*/
Var o = {
"M +": this. getMonth () + 1, // month
"D +": this. getDate (), // day
"H +": this. getHours (), // hour
"M +": this. getMinutes (), // minute
"S +": this. getSeconds (), // second
"Q +": Math. floor (this. getMonth () + 3)/3), // quarter
"S": this. getMilliseconds ()
// Millisecond
}
If (/(y +)/. test (format )){
Format = format. replace (RegExp. $1, (this. getFullYear () + "")
. Substr (4-RegExp. $1. length ));
}
For (var k in o ){
If (new RegExp ("(" + k + ")"). test (format )){
Format = format. replace (RegExp. $1, RegExp. $1. length = 1? O [k]
: ("00" + o [k]). substr ("" + o [k]). length ));
}
}
Return format;
}
// Format the title information
Function FormatContent (word, length ){
Return word. length> length? Word. substring (0, length) + "...": word;
}
</Script>