国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JQERY limittext 插件0.2版(長內容限制顯示)

2019-11-21 00:16:25
字體:
來源:轉載
供稿:網友
增加一個顯示更多的功能 附上代碼:使用實例在附件
復制代碼 代碼如下:

/**
* 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 "<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;
}
});

打包下載地址 //m.survivalescaperooms.com/jiaoben/29345.html
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高阳县| 长海县| 武平县| 马鞍山市| 长子县| 丹凤县| 牙克石市| 潞西市| 肥乡县| 阳春市| 沙湾县| 潜山县| 麟游县| 稻城县| 商河县| 永泰县| 英吉沙县| 通道| 西林县| 和田县| 洛宁县| 屯门区| 宽城| 磐石市| 新乡县| 大渡口区| 广南县| 鹤庆县| 大关县| 宣汉县| 鹰潭市| 伊金霍洛旗| 城固县| 凉山| 夏津县| 邯郸县| 安徽省| 钦州市| 乐山市| 通城县| 贵州省|