jQuery中$.fn的用法
原文:http://www.jb51.net/article/42816.htm
$.fn是指jquery的命名空间,$.fn=$.prototype。
1.$.extend
为jquery添加静态方法,与$.support,$.each类似
$.extend({
add:function(a,b){returna+b;}
});
$.add(1,2);
function test(){
function nPlugin(){
alert('1');
alert(this.add(1,4));
}
//与nPlugin.prototype.add=function(a,b){} 同
$.extend(nPlugin.prototype,{
add:function(a,b){return a+b;} ,
plus:function(a,b){return a*b}
});
}
$(function () {
alert(11111);
test();
$.nPlugin();//失效
nPlugin(); //失效
var a=new nPlugin();//有效
21 a.add(1,2);
});
2.$.fn.extend(object)
函数
$.fn.extend({
alertWhileClick:function(){
alert('1111111111')
});
}
});
$('#div').alertWhileClick();
对象
function test(){
var defaults = {
width: 200,
height: 0,
event: 'click touchstart' // click, touchstart
};
function nPlugin(element,options){
this.element = element;
this.settings = $.extend({}, defaults, options);
//alert($(element).html())
alert('1');
alert(this.add(1,4));
obj =this;
$(this.element).bind('click',function(){
obj.show();
});
}
//与nPlugin.prototype.add=function(a,b){} 同
$.extend(nPlugin.prototype,{
add:function(a,b){return a+b;} ,
plus:function(a,b){return a*b},
show:function(){
alert($(this.element).html())
}
});
//与$.fn.extend({nPlugin:funtion(){ }}) 同
//与$.fn.nPlugin=function(){} 同
$.fn['nPlugin'] = function(options) {
this.each(function() {
if (!$.data(this, "plugin_"+ "nPlugin")) {
$.data(this, "plugin_" + "nPlugin", new nPlugin(this, options));
//new Plugin(this, options);
}
});
return this;
};
}
$(function () {
test();
alert('333333333333')
$('#text').nPlugin();
$('#text').nPlugin().data('plugin_nPlugin').show();
});
jQuery中$.fn的用法的更多相关文章
- jQuery中$.fn的用法示例介绍
$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效,下面有个不错的示例,喜欢的朋友可以参考下 如扩展$.fn.abc(),即$.fn.abc()是对jquery ...
- jquery 之$.fn的用法示例
$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效. 若扩展$.fn.abc(),即$.fn.abc()是对jquery扩展一个abc的方法,那么每个jquer ...
- jquery中的$.fn的用法
JQuery里的原型prototype分析 http://www.nowamagic.net/librarys/veda/detail/653 jquery中的$.fn的用法 ...
- jQuery中on()方法用法实例详解
这篇文章主要介绍了jQuery中on()方法用法,实例分析了on()方法的功能及各种常见的使用技巧,并对比分析了与bind(),live(),delegate()等方法的区别,需要的朋友可以参考下 本 ...
- jQuery中on()方法用法实例
这篇文章主要介绍了jQuery中on()方法用法,实例分析了on()方法的功能.定义及在匹配元素上绑定一个或者多个事件处理函数的使用技巧,需要的朋友可以参考下 本文实例讲述了jQuery中on()方法 ...
- jQuery中Animate进阶用法(一)
jQuery中animate的用法你了解多少呢?如果仅仅是简单的移动位置,显示隐藏,哦!天哪你在浪费资源!因为animate太强大了,你可以有很多意想不到的用法!让我们一起研究一下吧~~ 首先要了解j ...
- jQuery中eq()方法用法实例
本文实例讲述了jQuery中eq()方法用法.分享给大家供大家参考.具体分析如下: 此方法能够获取匹配元素集上的相应位置索引的元素. 匹配元素集上元素的位置索引是从0开始的. 语法结构: 复制代码 代 ...
- jquery.validate.min.js 用法方法示例
页面html 代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- jQuery中attr()方法用法实例
本文实例讲述了jQuery中attr()方法用法.分享给大家供大家参考.具体分析如下: 此方法设置或返回匹配元素的属性值. attr()方法根据参数的不同,功能也不同. 语法结构一: 获取第一个匹配元 ...
随机推荐
- POJ2186
poj2186 popular cows Every cow's dream is to become the most popular cow in the herd. In a herd of ...
- iOS中坐标转换
坐标转换,可以用UIVIew的方法 //由要转换坐标view的superView执行该方法,rect为待转换view的frame,view是要显示到哪儿的 - (CGRect)convertRect: ...
- X-Forwarded-For (IIS日志记录用户真实IP)
参考:http://www.jbxue.com/article/7521.html 当IIS放在反向代理后面时,日志中的客户端ip是反向代理服务器的ip,不是用户的真实IP地址. 本文为大家介绍使用X ...
- perl chomp
在寻找k_word时,为了去打末尾的换行符,使用chomp;但 在windows下创建的的文件,读取一行,如一行为 weather 把它赋值为$str,然后print length($str),得 ...
- javascript一些方法兼容
javascript一些方法兼容 标签(空格分隔): javascript 方法收集 [TOC] Object.keys 参考地址 if (!Object.keys) Object.keys = fu ...
- java第6次作业
import java.util.ArrayList; import java.util.Collections; import java.util.Random; import java.util. ...
- xenomai for at91
http://www.at91.com/linux4sam/bin/view/Linux4SAM/RealTime#Xenomai
- IIS配置excel 权限
http://www.cnblogs.com/zhuxiaohui/archive/2013/10/16/3371637.html
- 使用 KGDB 调试 Kernel On Red Hat Linux
1. KGDB 简介 KGDB 提供了一种使用 GDB 调试 Linux 内核的机制.使用 KGDB 可以象调试普通的应用程序那样,在内核中进行设置断点.检查变量值.单步跟踪程序运行 ...
- bind原理 附带上自己的一些理解 (引自javascript设计模式和与看法实践)
Function.prototype.bind = function(){ //this指向的是所有由Function构造器产生的函数 var self = this, // 保存原函数 //[] ...