关于jquery.fn http://blog.sina.com.cn/s/blog_83958bc601012cl9.html
来源:互联网 发布:郑州黑马程序员官网 编辑:程序博客网 时间:2024/06/06 15:59
query $.fn $.fx是什么意思
$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效。
如扩展$.fn.abc(),即$.fn.abc()是对jquery扩展了一个abc方法,那么后面你的每一个jquery实例都可以引用这个方法了.
那么你可以这样子:$("#div").abc();
通常使用extend方法扩展,详细请看API.
jQuery为开发插件提拱了两个方法,分别是:
jQuery.fn.extend(object);
jQuery.extend(object);
jQuery.extend(object); 为扩展jQuery类本身.为类添加新的方法。
jQuery.fn.extend(object);给jQuery对象添加方法。
fn 是什么东西呢。查看jQuery代码,就不难发现。
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {//....
//......
};
原来 jQuery.fn = jQuery.prototype.对prototype肯定不会陌生啦。
虽然 javascript 没有明确的类的概念,但是用类来理解它,会更方便。
jQuery便是一个封装得非常好的类,比如我们用 语句 $("#btn1") 会生成一个 jQuery类的实例。
jQuery.extend(object); 为jQuery类添加添加类方法,可以理解为添加静态方法。如:
$.extend({
add:function(a,b){return a+b;}
});
便为 jQuery 添加一个为 add 的 “静态方法”,之后便可以在引入 jQuery 的地方,使用这个方法了,
$.add(3,4); //return 7
jQuery.fn.extend(object); 对jQuery.prototype进得扩展,就是为jQuery类添加“成员函数”。jQuery类的实例可以使用这个“成员函数”。
比如我们要开发一个插件,做一个特殊的编辑框,当它被点击时,便alert 当前编辑框里的内容。可以这么做:
Java代码
$.fn.extend({
});
$("#input1").alertWhileClick(); //页面上为:<input id="input1" type="text"/>
$("#input1") 为一个jQuery实例,当它调用成员方法 alertWhileClick后,便实现了扩展,每次被点击时它会先弹出目前编辑里的内容。
- 关于jquery.fn http://blog.sina.com.cn/s/blog_83958bc601012cl9.html
- http://blog.sina.com.cn/s/blog_5f8817250100g1dj.html
- http://blog.sina.com.cn/s/blog_5dfb7f4d0100j5e6.html
- http://blog.sina.com.cn/s/articlelist_1587621077_0_1.html
- http://blog.sina.com.cn/s/blog_8820018a0100w7t7.html
- http://blog.sina.com.cn/s/articlelist_1973273451_0_1.html
- http://blog.sina.com.cn/s/articlelist_1454293451_0_1.html
- http://blog.sina.com.cn/s/articlelist_1229508141_0_1.html
- http://blog.sina.com.cn/s/blog_4e6dffee0100hid1.html
- http://blog.sina.com.cn/s/blog_4ac0a0d30100cp9d.html
- http://blog.sina.com.cn/s/blog_77dd2fd20100y9vc.html
- http://blog.sina.com.cn/s/blog_61d8dfdb0100fti3.html
- http://blog.sina.com.cn/s/blog_65e943e70101est7.html
- http://blog.sina.com.cn/s/blog_8337d0c50100xn1p.html
- http://blog.sina.com.cn/s/blog_43eb83b90102dyl3.html
- http://blog.sina.com.cn/s/blog_3fe961ae01012tid.html
- http://blog.sina.com.cn/s/blog_53828e460100mv0d.html
- http://blog.sina.com.cn/s/blog_49867dc00100zj7t.html
- Linux内核中TCP的连接跟踪(2)
- 用Visual Studio 2010创建SharePoint外部列表
- Linux驱动程序开发实例
- LZW编码算法详解
- 两种方法实现---字符串倒叙
- 关于jquery.fn http://blog.sina.com.cn/s/blog_83958bc601012cl9.html
- Linux 四核4G内存320G硬盘分区推荐
- 开发人员的吐槽
- JAVA中try,catch,finally的return研究
- Android RTC 自下而上分析
- hdu 4281 judges' response
- 从Camera来看Binder IPC机制
- 紫薇花开的季节(二)
- 搭建了一个mini2440开发板u-boot的框架(1)