<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = GB2312"/>
<Title> JS </title>
</Head>
<Body>
<Div id = "content"> one kind of mentality is put down; one kind of realm is willing; one kind of happiness is waiting; one kind of wisdom is low-key; and the other is giving up; there is a kind of understanding that is confused; there is a kind of mentality that is inclusive; there is a kind of happiness that is simple; there is a kind of virtue that is called smile; there is a kind of happiness that is cherished; there is a kind of beauty that is confidence; there is a kind of emotion called sharing; there is a kind of truth called caring; there is a kind of warmth called gratitude; there is a kind of success called persistence.
</Div>
<Script language = "javascript"> www.2cto.com
(Function (){
Var len = 50; // The default number of words displayed
Var content = document. getElementById ("content"); // content gets the content div object
Var text = content. innerHTML; // text is the content
Var span = document. createElement ("span"); // create a SPAN tag
Var n = document. createElement ("a"); // create A tag
Span. innerHTML = text. substring (0, len); // the content of the SPAN tag is the first len character of text.
N. innerHTML = text. length> len? ".. Expand": ""; // the content of the created A tag. If the number of words in the content exceeds len, it is "... expand". Otherwise, it is null.
N. href = "javascript: void (0)"; // set the link address of tag A (random)
N. onclick = function () {// click the link to execute the following function:
// If the content of tag A is "... expand", the content of tag A is changed to "collapse", and the content of tag SPAN is all the content of DIV; otherwise, the content is the first len character.
If (n. innerHTML = "... expand "){
N. innerHTML = "hide ";
Span. innerHTML = text;
} Else {
N. innerHTML = "... expand ";
Span. innerHTML = text. substring (0, len );
}
}
Content. innerHTML = ""; // sets the DIV content to null.
Content. appendChild (span); // Add the SPAN element to the DIV.
Content. appendChild (n); // Add Element A to the DIV
})();
</Script>
</Body>
</Html>
:
From Lee.'s column