JQuery-based code for capturing RSS on the homepage of the blog Park

Source: Internet
Author: User

:

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.