jquery的扩展之extend函数
1.$.extend()使用
作用:扩展全局的函数
$.extend({
sayHellow:function(pram){
alert(pram+"hellow");
}
})
使用:
$(function({
$.sayHellow();
}))
jQuery.hellow = function() {
alert('hellow ');
};
jQuery.byebye = function(param) {
alert(param + 'byebye ');
};
使用:jQuery.hellow ();jQuery.byebye ('haha');
$.hellow ();$.byebye ('haha');
使用$.extend()扩展多个函数:
jQuery.extend({
hellow: function() {alert('hellow '); },
byebye: function(param) {alert(param + 'byebye ');}
});
使用命名空间:
第一种方法:
jQuery.myPlugin={ hellow: function() {alert('hellow '); }, byebye: function(param) {alert(param + 'byebye ');}
};
使用:
$.myPlugin.hellow();
$.myPlugin.byebye('haha'); 第二种方法: $.extend({myPlugin:{}}); $.extend({$.myPlugin,{
hellow: function() {alert('hellow '); }, byebye: function(param) {alert(param + 'byebye ');} }})
2.$.fn.extend()使用
作用:扩展的是jquery的实例对象的函数(jquery.fn=jquery.prototype)
$.fn.extend({
sayHellow:function(pram){
alert(pram+"hellow");
}
})
等于:
$.fn.sayHellow = function(pram) {
alert(pram+'hellow');
};
使用:$(" ").sayHellow(pram);
附加:定义了一个jQuery函数,形参是$,函数定义完成之后,把jQuery这个实参传递进去.立即调用执行。这样的好处是,我们在写jQuery插件时,也可以使用$这个别名,而不会与prototype引起冲突.
(function($) {
$.fn.pluginName = function() {
};
})(jQuery);
3.接受参数options控制的插件
$.fn.pulginName = function(options) {
var defaults = {
property1: '',
property2: '' };
var opts = $.extend(defaults, options);
};
调用:
$('#div').hilight({
property2: ''
});
这是一个很不错的博客:http://www.iteye.com/topic/545971
jquery的扩展之extend函数的更多相关文章
- jQuery对象扩展方法(Extend)深度解析
1.这几天在写自己的Js工具类库,所以在编写对象扩展方法,参考了jQuery的对象扩展方法,在编写该方法前,需要掌握js深拷贝和浅拷贝的相关知识,下面是jQuery3.2.1版本对象扩展方法的源码: ...
- jquery中方法扩展 ($.fn & $.extend) 学习笔记
A.$.fn 1.$.fn.method() 函数为jQuery对象扩展一个属性和方法(主要用于扩展方法) :method 为自定义方法名 ($.fn 等效 $.prototype) $.fn.bor ...
- jQuery.extend 函数
jQuery.extend 函数详解 JQuery的extend扩展方法: Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解. 一.J ...
- 【转载】jQuery.extend 函数详解
转载自:http://www.cnblogs.com/RascallySnake/archive/2010/05/07/1729563.html jQuery.extend 函数详解 JQuery的e ...
- jQuery.extend 函数详解
JQuery的extend扩展方法: Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解. 一.Jquery的扩展方 ...
- [转载]jQuery.extend 函数详解
JQuery的extend扩展方法: Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解. 一.Jquery的扩展方 ...
- (转)jQuery.extend 函数详解
Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解 JQuery的extend扩展方法: Jquery的扩展方法extend ...
- jQuery.extend 函数使用详解
JQuery的extend扩展方法: Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解. 一.Jquery的扩展方 ...
- jQuery.extend 函数使用
JQuery的extend扩展方法: Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解. 一.Jquery的扩展方 ...
随机推荐
- background: url 背景图片加时间戳不显示图片
在项目中一段这样的代码 背景图片加时间戳图片显示不出来 <div id="header" class="header clearfix" style=&q ...
- ✡ leetcode 166. Fraction to Recurring Decimal 分数转换 --------- java
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- 《C与指针》第七章练习
本章问题 1.具有空函数体的函数可以作为存根使用,你如何对这类函数进行修改,使其更有用? answer:Have the stub(存根) print out a message when it is ...
- 理解Linux系统负荷
一.查看系统负荷 如果你的电脑很慢,你或许想查看一下,它的工作量是否太大了. 在Linux系统中,我们一般使用uptime命令查看(w命令和top命令也行).(另外,它们在苹果公司的Mac电脑上也适用 ...
- Netflix Falcor获取JSON数据
Netflix开源了JavaScript库Falcor,它为从多个来源获取JSON数据提供了模型和异步机制. Netflix利用Falcor库实现通过JSON数据填充他们网页应用的用户界面.所有来自内 ...
- jQuery HTML节点元素修改、追加的方法 html()、append()、prepend()、
我们先拟定一个代码场景 <div>start</div> <p>123</p> <div>end</div> html() 操作 ...
- [Linux] VirtualBox - 主机与虚拟机互通 - CentOS
使用VirtualBox的主机与虚拟机相互通信方法: (使用VirtualBox不要使用绿色版的,因为绿色版的没有安装虚拟网卡驱动,所以主机与虚拟机是不能相互通信的,切记) 1.设置已经安装好的操作系 ...
- angular+bootstrap+MVC--之一,入门
这篇直奔MVVM主题,本例实现一个bootstrap的下拉框. 展示了如下技术: 1.MVVM绑定(事件绑定,值绑定,循环绑定,循环绑定中嵌套事件并回传item), 2.angul多module, 建 ...
- ADF_Desktop Integration系列4_ADF桌面集成入门之部署ADF Desktop Excel
2013-05-01 Created By BaoXinjian
- 在 Windows上配置NativeScript CLI
1.安装Node.js,到https://nodejs.org/下载安装 2.安装Chocolatey,https://chocolatey.org/,先看一下关于chocolatey的介绍: 安装方 ...