How to use a more intelligent intercept string length

82 0

Now use the method to compare soil, every time you need to implement it, don't know whether you've a more robust method or a library for reference.

if(string.length> 100) {
 string = string.substring(0,100)+"...";
}
3 Answers

82 1

can actually use css to achieve this effect, and this is better than any of the js. The code is as follows:

.overflowStringContainer{width:300px;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}

The text overflow is initially a private property of ie, which is now included in css3, and the compatibility list can be viewed: : http://www. Zhangxinxu. com/css3/css3-t., with 2011. 11. 7, ie, firefox, opera, safari, chrome, the latest version of chrome has fully support this property.

71 5
74 3
...