JQERY limittext 插件0.2版(長內(nèi)容限制顯示)
更新時間:2010年08月27日 20:10:17 作者:
JQERY limittext 插件為長內(nèi)容增加一個顯示更多的功能
增加一個顯示更多的功能 附上代碼:使用實例在附件
/**
* demo:
* 1.$("#limittext").limittext();
* 2.$("#limittext").limittext({"limit":1});
* 3.$("#limittext").limittext({"limit":1,"fill":"......","morefn":{"status":true}});
* 4.$("#limittext").limittext({"limit":1,"fill":"......","morefn":{"status":true,"moretext":"更多","lesstext":"隱藏部分","fullfn":function(){alert("more")},"lessfn":function(){alert("less")}}})
* 5.$("#limittext").limittext({"limit":1,"fill":"......","morefn":{"status":true}}).limit("all");
* @param {Object} opt
* {
* limit:30,//顯示文字個數(shù)
* fill:'...'//隱藏時候填充的文字
* morefn:{
* status:false,//是否啟用更多
* moretext: "(more)",//隱藏部分文字時候顯示的文字
* lesstext:"(less)",//全部文字時候顯示的文字
* cssclass:"limittextclass",//啟用更多的A標簽的CSS類名
* lessfn:function(){},//當文字為更少顯示時候回調(diào)函數(shù)
* fullfn:function(){}//當文字為更多時候回調(diào)函數(shù)
* }
* @author Lonely
* @link http://www.liushan.net
* @version 0.2
*/
jQuery.fn.extend({
limittext:function(opt){
opt=$.extend({
"limit":30,
"fill":"..."
},opt);
opt.morefn=$.extend({
"status": false,
"moretext": "(more)",
"lesstext":"(less)",
"cssclass": "limittextclass",
"lessfn": function(){
},
"fullfn": function(){
}
},opt.morefn);
var othis=this;
var $this=$(othis);
var body=$this.data('body');
if(body==null){
body=$this.html();
$this.data('body',body);
}
var getbuttom=function(showtext){
return "<a href='javascript:;' class='"
+opt.morefn.cssclass+"'>"
+showtext
+"<a>";
}
this.limit=function(limit){
if(body.length<=limit||limit=='all'){
var showbody=body+(opt.morefn.status?getbuttom(opt.morefn.lesstext):"");
}else{
if(!opt.morefn.status){
var showbody=body.substring(0,limit)
+opt.fill;
}else{
var showbody=body.substring(0,limit)
+opt.fill
+getbuttom(opt.morefn.moretext);
}
}
$this.html(showbody);
}
this.limit(opt.limit);
$("."+opt.morefn.cssclass).live("click",function(){
if($(this).html()==opt.morefn.moretext){
showbody=body
+getbuttom(opt.morefn.lesstext);
$this.html(showbody);
opt.morefn.fullfn();
}else{
othis.limit(opt.limit);
opt.morefn.lessfn();
}
});
return this;
}
});
打包下載地址 http://www.dbjr.com.cn/jiaoben/29345.html
復制代碼 代碼如下:
/**
* demo:
* 1.$("#limittext").limittext();
* 2.$("#limittext").limittext({"limit":1});
* 3.$("#limittext").limittext({"limit":1,"fill":"......","morefn":{"status":true}});
* 4.$("#limittext").limittext({"limit":1,"fill":"......","morefn":{"status":true,"moretext":"更多","lesstext":"隱藏部分","fullfn":function(){alert("more")},"lessfn":function(){alert("less")}}})
* 5.$("#limittext").limittext({"limit":1,"fill":"......","morefn":{"status":true}}).limit("all");
* @param {Object} opt
* {
* limit:30,//顯示文字個數(shù)
* fill:'...'//隱藏時候填充的文字
* morefn:{
* status:false,//是否啟用更多
* moretext: "(more)",//隱藏部分文字時候顯示的文字
* lesstext:"(less)",//全部文字時候顯示的文字
* cssclass:"limittextclass",//啟用更多的A標簽的CSS類名
* lessfn:function(){},//當文字為更少顯示時候回調(diào)函數(shù)
* fullfn:function(){}//當文字為更多時候回調(diào)函數(shù)
* }
* @author Lonely
* @link http://www.liushan.net
* @version 0.2
*/
jQuery.fn.extend({
limittext:function(opt){
opt=$.extend({
"limit":30,
"fill":"..."
},opt);
opt.morefn=$.extend({
"status": false,
"moretext": "(more)",
"lesstext":"(less)",
"cssclass": "limittextclass",
"lessfn": function(){
},
"fullfn": function(){
}
},opt.morefn);
var othis=this;
var $this=$(othis);
var body=$this.data('body');
if(body==null){
body=$this.html();
$this.data('body',body);
}
var getbuttom=function(showtext){
return "<a href='javascript:;' class='"
+opt.morefn.cssclass+"'>"
+showtext
+"<a>";
}
this.limit=function(limit){
if(body.length<=limit||limit=='all'){
var showbody=body+(opt.morefn.status?getbuttom(opt.morefn.lesstext):"");
}else{
if(!opt.morefn.status){
var showbody=body.substring(0,limit)
+opt.fill;
}else{
var showbody=body.substring(0,limit)
+opt.fill
+getbuttom(opt.morefn.moretext);
}
}
$this.html(showbody);
}
this.limit(opt.limit);
$("."+opt.morefn.cssclass).live("click",function(){
if($(this).html()==opt.morefn.moretext){
showbody=body
+getbuttom(opt.morefn.lesstext);
$this.html(showbody);
opt.morefn.fullfn();
}else{
othis.limit(opt.limit);
opt.morefn.lessfn();
}
});
return this;
}
});
打包下載地址 http://www.dbjr.com.cn/jiaoben/29345.html
相關文章
jQuery 學習第七課 擴展jQuery的功能 插件開發(fā)
在介紹如何擴展jQuery之前,先大致看下jQuery源碼(以1.3.2版本為例)。2010-05-05自己動手實現(xiàn)jQuery Callbacks完整功能代碼詳解
最近大量的用到jQuery Callbacks 對象,jQuery庫中的$.ajax()和$.Deferred() 對象也是基于這個對象實現(xiàn),下面我們也模擬實現(xiàn)jQuery Callbacks 對象的部分功能2013-11-11jQuery實現(xiàn)鼠標經(jīng)過顯示動畫邊框特效
本文主要介紹了jQuery鼠標經(jīng)過顯示動畫邊框特效的實例代碼。具有很好的參考價值。下面跟著小編一起來看下吧2017-03-03Tab頁界面 用jQuery及Ajax技術實現(xiàn)(php后臺)
到了B/S開發(fā)時代,網(wǎng)頁前端布局也把Tab頁的布局形式吸收了過來。特別是和Ajax技術結(jié)合起來,可以更充分發(fā)揮Tab頁的良好表現(xiàn)力和數(shù)據(jù)緩存的優(yōu)勢,是一種良好的網(wǎng)頁布局形式2011-10-10jQuery+ajax實現(xiàn)修改密碼驗證功能實例詳解
本文通過實例代碼給大家介紹了jQuery+ajax實現(xiàn)修改密碼驗證功能,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的的朋友參考下吧2017-07-07