最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

CSS(js)限制頁面顯示的文本字符長度

 更新時間:2012年12月27日 17:46:09   作者:  
限制頁面顯示的字符長度,一直被眾多網(wǎng)友傾睬,本人也是一fans利用閑暇時間搜集整理了一些實用技巧,需要了解的朋友可以參考下
復(fù)制代碼 代碼如下:

<nav class="cf_nav clearfix">
<ul>
<li>
<a title="首頁">
<div class="nav_block">
<span>首頁</span>
<span class="hover">首頁</span>
</div>
</a>
</li>
<li>
<a title="投稿">
<div class="nav_block">
<span>投稿</span>
<span class="hover">投稿</span>
</div>
</a>
</li>
<li>
<a title="私信 ">
<div class="nav_block">
<span>私信 </span>
<span class="hover">私信 </span>
</div>
</a>
</li>
<li>
<a title="存檔">
<div class="nav_block">
<span>存檔</span>
<span class="hover">存檔</span>
</div>
</a>
</li>
<li>
<a title="訂閱">
<div class="nav_block">
<span>訂閱</span>
<span class="hover">訂閱</span>
</div>
</a>
</li>

如果我在限制上面的span中的字符。
$("nav_block span").wordLimit(8);
它使用了下面的一個算定義jquery插件的方法,這是我從點點網(wǎng)扣下來的:
復(fù)制代碼 代碼如下:

// copyright c by zhangxinxu v1.0 2009-09-05
// http://www.zhangxinxu.com
/* $(".test1").wordLimit(); 自動獲取css寬度進行處理,如果css中未對.test1給定寬度,則不起作用
$(".test2").wordLimit(24); 截取字符數(shù),值為大于0的整數(shù),這里表示class為test2的標(biāo)簽內(nèi)字符數(shù)最多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(); //清除復(fù)制
return;
}
}else{
var maxwidth=num;
if($(this).text().length>maxwidth){
$(this).text($(this).text().substring(0,maxwidth));
$(this).html($(this).html()+'...');
}
}
});
}
})(jQuery);

相關(guān)文章

最新評論

扶余县| 合江县| 汤阴县| 清苑县| 龙门县| 资源县| 祥云县| 烟台市| 凉城县| 黑龙江省| 葫芦岛市| 当阳市| 唐海县| 桃园县| 东宁县| 荆门市| 泰顺县| 洪湖市| 集贤县| 高碑店市| 杭州市| 和平区| 枞阳县| 吉木萨尔县| 明光市| 饶平县| 星子县| 伊宁市| 千阳县| 龙胜| 云龙县| 宜良县| 疏附县| 和龙市| 八宿县| 桐梓县| 古丈县| 舞阳县| 巴彦县| 尼玛县| 吉安市|