Home > Web Front-end > JS Tutorial > body text

jquery 插件学习(一)_jquery

WBOY
Release: 2016-05-16 17:51:08
Original
921 people have browsed it

言归正传拉,开始跟我学习吧:);

1.jquery自定义了 jQuery.extend()和jQuery.fn.extend()方法,其中,jQuery.extend()方法能够创建全局函数或者选择器,而jQuery.fn.extend()能够创建jQuery对象方法。在这里啰嗦讲下:这2个方法,都包含一个参数,改参数仅接受名/值对结构的对象,其中名表示函数或方法名,而值表示函数体。

复制代码 代码如下:

jQuery.extend({
minValue : function(a,b){
return a>b? b:a;
},
maxValue : function(a,b){
return a},
})


复制代码 代码如下:

<script> <BR>$(function(){ <BR>$('input').click(function(){ <BR>var a = prompt("请输入一个值"); <BR>var b = prompt("请输入一个值"); <BR>var c = jQuery.minValue(a,b); <BR>var d = jQuery.maxValue(a,b); <BR>alert("你输入的最小值:"+c+"\n你输入的最大值:"+d); <BR>}); <BR>}); <BR><script> <BR></script>



在实际开发中,jQuery.extend()方法,为插件方法传递系列选项结构的参数。
复制代码 代码如下:

function fn(options){
var options = jQuery.extend({name1: value1,name2 :value2,name3 : value3},options);
//函数体
}

调用:
fn({name1:value2,name2:jine,name3:hx});//覆盖新值
fn({name4:value2,name5:jine,});//添加新选项
fn();//保持默认值

未完待续。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!