1. Intercept through CSS. However, we need to differentiate IE, ff, and other browsers.
<Style type = "text/CSS">
. DS
{
Max-width: 95px;/* the width of the layer. */
}
.
{
Display: block;/* defined as block level */
Width: 90px;/* width of the text to be displayed */
Float: Left;/* left alignment */
Overflow: hidden;/* Hide the excess parts. */
White-space: nowrap ;/**/
Padding-Right: 10px;/* The text is 7 pixels away from the right side. */
Text-overflow: ellipsis;/* replace the ellipsis (...) When IE is not displayed */
-O-text-overflow: ellipsis;/* replace the ellipsis (...) in the fields not displayed by opera */
}
. DS: After
{
Content :"...";
}
/* Supports Firefox */</style>
2. Intercept through custom methods
Public Static String [] Intercept ( String Input, Int P)
{
String [] strinput = New String [ 2 ];
Encoding encode = Encoding. getencoding ( " Gb2312 " );
Input = Input ?? String. empty;
Byte [] Bytearr = Encode. getbytes (input );
If (Bytearr. Length <= P)
{
Strinput [ 0 ] = Input;
Strinput [ 1 ] = "" ;
Return Strinput;
}
Int M = 0 , N = 0 ;
Foreach ( Byte B In Bytearr)
{
If (N > = P) Break ;
If (B > 127 ) M ++ ; // Important: Count the characters whose values in the first p bytes are greater than 127.
N ++ ;
}
If (M % 2 ! = 0 ) N = P + 1 ; // If it is not even: It indicates that the end is a double byte character, and the number of truncated digits is added to 1.
Strinput [ 0 ] = Encode. getstring (bytearr, 0 , N );
Strinput [ 1 ] = Encode. getstring (bytearr, N, bytearr. Length - N );
Return Strinput;
}
3. Intercept through Js.
< Script Type = " Text/JavaScript " >
$ (Function() {Myfunction ();})
FunctionMyfunction (){
VaRJj=Document. getelementbyid ("Jj"). Innertext;
If (JJ. Length > 100 ){
Document. getelementbyid ( " Jj " ). Innerhtml = JJ. substring ( 0 , 99 ) + " <Span id = 'span1'> <a href = '# 'onclick = 'display (0)'>... expand </a> </span> <span id = 'span2' style = 'display: none; '> " + JJ. substring ( 99 , JJ. length) + " <A onclick = 'display (1) 'href =' # '> collapse </a> </span> "
}
}
Function Display (ID ){
If (ID = 0 ){
Document. getelementbyid ( " Span1 " ). Style. Display = " None " ;
Document. getelementbyid ( " Span2 " ). Style. Display = "" ;
} Else {
Document. getelementbyid ( " Span1 " ). Style. Display = "" ;
Document. getelementbyid ( " Span2 " ). Style. Display = " None " ;
}
}
</SCRIPT>