如何扩展jQuery的插件? [英] How to extend the plugin for jQuery?
本文介绍了如何扩展jQuery的插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为jQuery编写插件。我有扩展插件的问题。我编写了插件,例如: http://docs.jquery.com/Plugins/Authoring 。
I am writing the plugin for jQuery. I have the problem with the extension plugin. I wrote the plugin for example: http://docs.jquery.com/Plugins/Authoring.
请参阅以下示例代码:
(function($){
var i18n = {};
var methods = {};
$.fn.myPlugin = function(options){
//...
};
})(jQuery);
如何扩展属性 i18n
?
我希望能够支持存储在单独文件中的国际化插件设置。我该怎么办?
I want to be able to support the internationalization plug-in settings which are stored in the separate file. How should I do?
推荐答案
例如:
// plugin definition
$.fn.hilight = function(options) {
// Extend our default options with those provided.
// Note that the first arg to extend is an empty object -
// this is to keep from overriding our "defaults" object.
var opts = $.extend({}, $.fn.hilight.defaults, options);
// Our plugin implementation code goes here.
};
// plugin defaults - added as a property on our plugin function
$.fn.hilight.defaults = {
foreground: 'red',
background: 'yellow'
};
从这里 http://www.learningjquery.com/2007/10/a-plugin-development-pattern 。
这是一个非常好的教程,可以开始使用
This is a very nice tutorial to get started with
这篇关于如何扩展jQuery的插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文