JQERY limittext 플러그인 버전 0.2(긴 내용 제한 표시)

3024 단어
더 많은 기능을 표시하는 코드를 추가합니다: 첨부 파일에 실례를 사용합니다
 
  
/**
* 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,//
* fill:'...'//
* morefn:{
* status:false,//
* moretext: "(more)",//
* lesstext:"(less)",//
* cssclass:"limittextclass",// A CSS
* lessfn:function(){},//
* fullfn:function(){}//
* }
* @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 "" +showtext +""; } 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; } });

패키지 다운로드 주소//www.jb51.net/jiaoben/29345.html

좋은 웹페이지 즐겨찾기