JQERY limittext 插件0.2版(長內(nèi)容限制顯示)
更新時(shí)間:2010年08月27日 20:10:17 作者:
JQERY limittext 插件為長內(nèi)容增加一個(gè)顯示更多的功能
增加一個(gè)顯示更多的功能 附上代碼:使用實(shí)例在附件
/**
* 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,//顯示文字個(gè)數(shù)
* fill:'...'//隱藏時(shí)候填充的文字
* morefn:{
* status:false,//是否啟用更多
* moretext: "(more)",//隱藏部分文字時(shí)候顯示的文字
* lesstext:"(less)",//全部文字時(shí)候顯示的文字
* cssclass:"limittextclass",//啟用更多的A標(biāo)簽的CSS類名
* lessfn:function(){},//當(dāng)文字為更少顯示時(shí)候回調(diào)函數(shù)
* fullfn:function(){}//當(dāng)文字為更多時(shí)候回調(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://m.fzitv.net/jiaoben/29345.html
復(fù)制代碼 代碼如下:
/**
* 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,//顯示文字個(gè)數(shù)
* fill:'...'//隱藏時(shí)候填充的文字
* morefn:{
* status:false,//是否啟用更多
* moretext: "(more)",//隱藏部分文字時(shí)候顯示的文字
* lesstext:"(less)",//全部文字時(shí)候顯示的文字
* cssclass:"limittextclass",//啟用更多的A標(biāo)簽的CSS類名
* lessfn:function(){},//當(dāng)文字為更少顯示時(shí)候回調(diào)函數(shù)
* fullfn:function(){}//當(dāng)文字為更多時(shí)候回調(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://m.fzitv.net/jiaoben/29345.html
相關(guān)文章
ASP.NET jQuery 實(shí)例3 (在TextBox里面阻止復(fù)制、剪切和粘貼事件)
在這講里,讓我們看下如何在ASP.NET Textbox里禁止復(fù)制、剪切和粘貼行為2012-01-01
jQuery團(tuán)購倒計(jì)時(shí)特效實(shí)現(xiàn)方法
這篇文章主要介紹了jQuery團(tuán)購倒計(jì)時(shí)特效實(shí)現(xiàn)方法,可實(shí)現(xiàn)相對固定時(shí)間的倒計(jì)時(shí)效果,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-05-05
jQuery Ajax請求后臺數(shù)據(jù)并在前臺接收
這篇文章主要介紹了jQuery Ajax請求后臺數(shù)據(jù)并在前臺接收的相關(guān)資料,需要的朋友可以參考下2016-12-12
基于Jquery代碼實(shí)現(xiàn)支持PC端手機(jī)端幻燈片代碼
支持PC端手機(jī)端幻燈片代碼是一款支持移動(dòng)觸摸,支持鼠標(biāo)拖拽切換,支持帶進(jìn)度條的自動(dòng)播放模式,本文給大家分享一款基于jquery代碼實(shí)現(xiàn)支持pc端手機(jī)端幻燈片代碼,感興趣的朋友一起學(xué)習(xí)吧2015-11-11
javascript 歷史記錄 經(jīng)常用于產(chǎn)品最近歷史瀏覽
在很多購物網(wǎng)站,都有“產(chǎn)品的瀏覽歷史記錄”,這是個(gè)很貼心的功能。2009-05-05
Boostrap實(shí)現(xiàn)的登錄界面實(shí)例代碼
Bootstrap它是一個(gè)開源的web開發(fā)前端框架。本界面使用的Bootstrap是v3.3.5版本。這篇文章給大家?guī)砹嗽敿?xì)的實(shí)現(xiàn)代碼,非常不錯(cuò),感興趣的朋友一起看看吧2016-10-10

