<script type= "text/javascript" >
// Description: Use Javascript and CSS to achieve footnote effect
// Author: CodeBit.cn ( http://www.CodeBit.cn )
var footNotes = function ( ) { } ;
footNotes. prototype = {
footNoteClassName : "footnote" , // The className of the footnote
footNoteTagName : "span" , // The tag name of the footnote
footNoteBackLink : " [back]" , // Return to the link
format : function ( contentID, footnoteID )
{
if ( ! document.getElementById ) return false ;
var content = document.getElementById ( contentID ) ;
var footnote = document.getElementById ( footnoteID ) ;
var spans = content. getElementsByTagName ( this . footNoteTagName ) ;
var noteArr = [ ] ;
var note = 0 ;
var elContent;
var len = spans. length ;
for ( i= 0 ; i<len; i++ )
{
note ++;
if ( spans [ i ] . className == this . footNoteClassName )
{
// Get the footnote content
elContent = spans [ i ] . innerHTML ;
noteArr.push ( elContent ) ;
// Create a link to the footnote
var newEle = document. createElement ( "a" ) ;
newEle. href = '#ftn_' + footnoteID + '_' + note;
newEle. title = "show footnote" ;
newEle. id = 'ftnlink_' +footnoteID+ '_' + note;
newEle. innerHTML = note;
// Clear the original content
while ( spans [ i ] . childNodes . length )
{
spans [ i ] . removeChild ( spans [ i ] . firstChild ) ;
}
spans [ i ] . appendChild ( newEle ) ;
}
}
//Create a note list
var ul = this .__buildNoteList ( noteArr, footnoteID ) ;
footnote.appendChild ( ul ) ;
} ,
__buildNoteList : function ( notes, noteID )
{
if ( !notes || notes. length < 1 ) return ;
var ul = document. createElement ( 'ul' ) ;
ul.className = this .footNoteClassName ;
varli ;
var len = notes. length + 1 ;
for ( i= 1 ; i<len; i++ )
{
li = document. createElement ( 'li' ) ;
li. id = "ftn_" +noteID+ "_" +i;
li. innerHTML = notes [ i -1 ] ;
// Create a [return] link
var link = document. createElement ( "a" ) ;
link. href = "#ftnlink_" + noteID + "_" + i;
link. innerHTML = this . footNoteBackLink ;
li.appendChild ( link ) ;
ul.appendChild ( li ) ;
}
return ul;
}
} ;
</script>