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()方法根据参数的不同,功能也不同. 语法结构一: 获取第一个匹配元 ...
随机推荐
- win8 系统无法正常安装.net framework 2.0和3.0框架如何解决
在安装.net framework2.0框架的时候一直提示要用户从网上面下载框架,你点击下载好的安装包也是无法安装的.这个时候就需要你使用离线的安装包来进行问题的解答附件在此http://pan.ba ...
- Webstorm官方最新版本for Mac版本 不用注册码/破坏原文件
首先,说明下我自己安装的时候看到网上无外乎两种方法: 下载别人封装好的安装包,把JetbrainsCrack.jar复制到/Applications/WebStorm.app/Contents/bin ...
- java的Map及Map.Entry解析
Map<K,V>是以键-值对存储的(key-value), 而Entry<K,V>是Map中的一个接口,Map.Entry<K,V>接口主要用于获取.比较 key和 ...
- LINUX 更新
sudo apt-get dist-upgrade,更新所有的软件
- ZT 螨虫的话就不要跟狗多接触,狗的寄生虫很多,还有草地,
病情分析:过敏是治不好的,只能做到避免接触.指导意见:螨虫的话就不要跟狗多接触,狗的寄生虫很多,还有草地,尤其是狗经常去的地方,草地就是螨虫的传播介质.你是过敏性体质除了被免 过敏性源外,还要增强体质 ...
- Form表单(回车)提交问题
我们有时候希望回车键敲在文本框(input element)里来提交表单(form),但有时候又不希望如此.比如搜索行为,希望输入完关键词之后直接按回车键立即提交表单,而有些复杂表单,可能要避免回车键 ...
- CMakeLists for tesseract
在网上找了很多,直接用都不行,试了半天的到以下的结果. cmake_minimum_required(VERSION 2.8) project( test ) include_directories ...
- get_object_vars($var) vs array($var)
get_object_vars(\(var) vs array(\)var) test case class Test { public function actionGetObjectVarsVsA ...
- web测试方法总结
链接地址:http://www.cnblogs.com/Jessy/p/3539638.html 一.输入框 1.字符型输入框: (1)字符型输入框:英文全角.英文半角.数字.空或者空格.特殊字符“~ ...
- 用命令查看Mysql中数据库、表的空间大小
要想知道每个数据库的大小的话,步骤如下:1.进入information_schema 数据库(存放了其他的数据库的信息)use information_schema;2.查询所有数据的大小:selec ...