Home  >  Article  >  Web Front-end  >  Jquery 插件开发笔记整理_jquery

Jquery 插件开发笔记整理_jquery

WBOY
WBOYOriginal
2016-05-16 18:11:58888browse

只好自己来写个文章,已便日后记忆!
先贴出插件代码,里面注释

复制代码 代码如下:

(function ($) {
//扩展
$.fn.extend({
//插件名称
height: function (options) {
//默认参数
var defaults = {
color: '红色'
};
//覆盖默认参数
var opts = $.extend(defaults, options);
//主函数
return this.each(function () {
//激活事件
var obj = $(this);
obj.click(function () {
alert(opts.color);
});
});
}
})
})(jQuery);
//注后面的(jQuery)一定要这样,Q一定要大写,j不能大写,不然出错。

下面为使用代码
复制代码 代码如下:

@{
ViewBag.Title = "Home Page";
}
@section Header{


}

@ViewBag.Message



To learn more about ASP.NET MVC visit http://asp.net/mvc.



很简单吧,其实开发Jquery插件还有其它的方法,我只是感觉这种方法比较好,可读性也比较好。

jquery插件就写到这里!
Statement:
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