文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>jquery插件开发备注

jquery插件开发备注

时间:2010-08-31  来源:缘分星空

以前针对DOM元素的插件(即$.fn.)存临时数据都加在当前元素上建个特殊的属性来存,(JQ内部直接也搞这样的)

今天发现其实JQ自己早就有对这个临时数据的存储方法:

$("dom").data(“mydata”,"this is data");还有就是插件开发的时候我们经常要给插件添加方法,其实就用JS内部添加方法的方法即可

this.myfn=function(){}

下面给上一个显示部分文字的插件的源码:

(类似CSS的text-overflow,但本插件你需要提供显示几个字,用于精确控制显示数量)


/**
* demo:
* 1.$("#limittext").limittext();
* 2.$("#limittext").limittext({"limit":1});
* 3.$("#limittext").limittext({"limit":1,"fill":"(部分隐藏)","fillid":"aaa"});
* 4.$("#limittext").limittext({"limit":1,"fill":"(部分隐藏)","fillid":"aaa"}).limit(10); * 5.$("#limittext").limittext({"limit":1,"fill":"(部分隐藏)","fillid":"aaa"}).limit('all');
* @param {Object} opt
* @author Lonely * @link http://liushan.net
*/
jQuery.fn.extend({
limittext:function(opt){
opt=$.extend({
"limit":30,
"fill":"...",
"fillid":null
},opt);
var $this=$(this);
var body=$(this).data('body');
if(body==null){
body=$this.html();
$(this).data('body',body);
}
this.limit=function(limit){
if(body.length<=limit||limit=='all')
var showbody=body;
else{
if(opt.fillid==null)
var showbody=body.substring(0,limit)+opt.fill;
else
var showbody=body.substring(0,limit)+"<span id='"+opt.fillid+"'>"+opt.fill+"<span>";
}
$(this).html(showbody);
}
this.limit(opt.limit);
return this;
}
});

Gucci Designers Handbags 189895HX61G4061 gucci-189895HX61G4061Gucci wallet in dark coffee Gucci-181641-02 HandbagsChanel kelly bag in 35973 black carvier leather 35973black HandbagsLV N51181 Louis Vuitton LV Handbags Saleya GMGucci Wallet Gucci-43508 HandbagsGucci G148476 Brown leather messenger bag Gucci-148476L HandbagsGucci bag 203529 in Black Patent Leather Gucci-5-203529 Handbagschanel Handbags Chanel 2008 new Clutch 225 - grey chanel-225--greyLouis Vuitton Suhali Lockit Bag PM Blue M95431 HandbagsLV M95547RW Louis Vuitton Handbags Mahina S - CreamLouis Vuitton Damier Geant Canvas Aventurier Sandy M93061 HandbagsLouis Vuitton Multicolor Lodge PM White M40053 HandbagsSlouchy Denim Tote chanel-cc2360 HandbagsChanel Moscow Classic Flap Bag nappa leather 35995-Pink 35995pink HandbagsNew Handbags CC216 chanel-new-216-redClassic Chains Bag - Metallic Grey chanel-cc2160 HandbagsGucci 190336-white Gucci-190336 HandbagsLouis Vuitton Damier Canvas Sistina PM N41542 HandbagsLouis Vuitton Multicolor Aurelia GM White M40100 HandbagsNew Chanel Handbags CC223 chanel-35615LV M42350 Louis Vuitton LV Handbags Diaper Bag - BlueChanel Hobo Calfskin Bag Embossed With Chanel Signatures - Black 36009black Handbagschanel Wallet Caviar Clutch - Red Chanel-cc2090 HandbagsLouis Vuitton Epi Leather Petit Noe Black M59212 HandbagsLV M95684sd Louis Vuitton Handbags Whisper MM - ChocolateLouis Vuitton Suhali Leather Lockit PM Black M91888 HandbagsLouis Vuitton Cruise 2009 Traveller Pink M92806B HandbagsLV m95982 Louis Vuitton Collection Beach Casbas Ipanema PM Grey M95982 Handbags09 New Chanel Funny Tweed Patent Leather Shoulder Bag 36016 - Black 36016black HandbagsLouis Vuitton Monogram Canvas Bag M70311 HandbagsLouis Vuitton Tahitienne GM Beige M95675 HandbagsGucci bag 20786 in balck gucci-207286-Black HandbagsGucci 170051-Brown Evening Bag gucci-170051-02 HandbagsGucci 219704 BCC8G 1000 large shoulder bag GUCCI-219704-BCC8G-1000 HandbagsGucci wallet-brown Gucci-181895-04 HandbagsLouis Vuitton Epi Leather Shoulder Bag Ivory M4023M HandbagsLouis Vuitton Nomade Leather Nomade Keepall M85391 HandbagsLouis Vuitton Monogram Vernis Brentwood Amarante M91994 HandbagsGucci leather wallet Black Gucci-52185 HandbagsGucci 'gloss' evening bag 213767 B8Q3G 8236 Gucci-213767-B8Q3G-8236 HandbagsLouis Vuitton Multicolor Petite Noe White M42229 HandbagsLouis Vuitton Tahitienne PM Blueviolet M95680 HandbagsLouis Vuitton Sobe Clutch Amarante M93728 HandbagsLouis Vuitton Monogram Canvas Poche Documents M53456 HandbagsGucci GG Fabric Handbagss 153009-Black gucci-153009-BlackGucci GG Fabric Handbagss 181501-Coffee gucci-181501-CoffeeLV M58862R Louis Vuitton LV Handbags Ségur MM - RedChanel Handbags Chanel Coco Cabas Black Vinyl 34502- metallic gol Chanel-34502-metallic-goldLV M95552PL Louis Vuitton Handbags Mahina XS - Metallic PurpleGucci bag 181527 in Black Gucci-181527B Handbags
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载