<nav class= "Cf_nav clearfix" > <ul> <li> <a href= "Http://lizhu Angs.18021051d350c3871c0a.tpl.diandian.com "title=" Home "> <div class=" Nav_block "> <span> home Page &
lt;/span> <span class= "hover" > Home </span> </div> </a> </li> <li> <a href= "Http://lizhuangs.18021051d350c3871c0a.tpl.diandian.com/submit" title= "Submission" > &
Lt;div class= "Nav_block" > <span> submission </span> <span class= "hover" > Submission </span> </div> </a> </li> <li> <a href= "http://lizhuangs.diandian.co M/inbox "title=" DMS "> <div class=" nav_block "> <span> dms </span> <span class= "hover" > DMs </span> </div> </a> </li> <li> <a HR Ef= "http://lizhuangs.18021051d350c3871c0a.tpl.diandian.com/archive "title= Archive" > <div class= "Nav_block" > <span> Archive &
lt;/span> <span class= "hover" > Archive </span> </div> </a> </li> <li> <a href= "Http://lizhuangs.18021051d350c3871c0a.tpl.diandian.com/rss" title= "subscribe" > <div C lass= "Nav_block" > <span> subscriptions </span> <span class= "hover" > Subscribe to </span> ;/div> </a> </li>
If I'm limiting the characters in the span above.
$ ("Nav_block span"). Wordlimit (8);
It uses the following method to define the jquery plug-in, which I have deducted from the DOT network:
//copyright C by Zhangxinxu v1.0 2009-09-05//http://www.zhangxinxu.com/* $ (". Test1"). Wordlim It (); Automatically gets the CSS width for processing, and if the CSS does not have a width given to. test1, it does not work $ (". Test2"). Wordlimit (24); Intercepts the number of characters, which is an integer greater than 0, where the number of characters in the label class is Test2 is up to 24 */function ($) {$.fn.wordlimit = function (num) {This.each (function () {if (!num)
{var copythis = $ (This.clonenode (true)). Hide (). css ({' position ': ' absolute ', ' width ': ' Auto ', ' overflow ': ' Visible ')
});
$ (this). After (Copythis);
if (Copythis.width () >$ (this). Width ()) {$ (this). Text ($ (this). Text (). SUBSTRING (0,$ (this). Text (). length-4));
$ (this). HTML ($ (this). html () + ' ... ');
Copythis.remove ();
$ (this). Wordlimit ();
}else{copythis.remove ();//clear copy return;
}}else{var maxwidth=num;
if ($ (this). Text (). Length>maxwidth) {$ (a). Text ($ (this). Text (). substring (0,maxwidth));
$ (this). HTML ($ (this). html () + ' ... ');
}
}
}); }) (jQuery);