<Nav class = "cf_nav clearfix"> <ul> <li> <a href = "http://lizhuangs.18021051d350c3871c0a.tpl.diandian.com" title = "home"> <div class = "nav_block"> <span> Home </span> <span class = "hover"> Home </span> </div> </a> </li> <a href = "http://lizhuangs.18021051d350c3871c0a.tpl.diandian.com/submit" title = "contribution"> <div class = "nav_block"> <span> contribution </span> <span class = "hover"> contribution </span> </div> </ a> </li> <a href = "http://lizhuangs.diandian.com/inbox" title = "private message"> <div class = "nav_block"> <span> private message </span> <span class = "hover"> private message </span> </div> </a> </li> <a href = "http://lizhuangs.18021051d350c3871c0a.tpl.diandian.com/archive" title = "Archive "> <div class =" nav_block "> <span> archive </span> <span class =" hover "> archive </span> </div> </a> </li> <a href = "http://lizhuangs.18021051d350c3871c0a.tpl.diandian.com/rss" title = "subscribe"> <div class = "nav_block"> <span> subscription </span> <span class =" hover "> subscription </span> </div> </a> </li>
If I limit the characters in the span above.
$ ("Nav_block span"). wordLimit (8 );
It uses the following method to define the jquery plug-in, which I deducted from the dot net:
// Copyright c by zhangxinxu v1.0 2009-09-05 // http://www.zhangxinxu.com/* $ (". test1 "). wordLimit (); automatically obtains the css width for processing, if not in css. given the width of test1, $ (". test2 "). wordLimit (24); number of truncated characters. The value is an integer greater than 0. Here, it indicates that the number of characters in the label of class test2 can be 24 at most */(function ($) {$. fn. wordLimit = function (num) {this. each (function () {if (! Num) {var copyThis = (this.clonenode(true+}.hide().css ({'position': 'absolute ', 'width': 'auto', 'overflow': 'visable'}); $ (this ). after (copyThis); if (copyThis. width ()> trim () + '... '); copyThis. remove (); $ (this ). wordLimit ();} else {copyThis. remove (); // Clear copy return;} else {var maxwidth = num; if ($ (this ). text (). length> values () + '... ') ;}}) ;}} (jQuery );