2007年11月10日 星期六

「繼續閱讀」功能分析

之前,我想說blog首頁文章這麼多又滿長的,

閱讀起來不太方便,

所以就去找了個繼續閱讀的功能。

當時對javascript不太熟,也沒再深究。

不過今天總算是學了一點皮毛了,

就來看看它到底做了什麼吧!

繼續閱讀:From Chagg's 嘴砲日記


function hidePost(postUrl)
{
var label=document.getElementById("fullpost");
//抓有"fullpost"的部分
if(label!=null) //如果存在的話,
{
eA = document.createElement("a"); //建立一個超連結,就是<a>
eA.setAttribute("href",postUrl); //它將會連到該篇文章的頁面
eA.setAttribute("title","To be continued...");
//在裡面加入文字
eA.appendChild(document.createTextNode("To be continued..."));

//把上面的超連結包在一個段落標籤裡
eB = document.createElement("p");
eB.setAttribute("id","read-more");
eB.appendChild(eA);
//在本文裡加入上面那個標籤。
label.parentNode.appendChild(eB);
//移除本文裡,被"fullpost"包住的文字。
label.parentNode.removeChild(label);
}
}