公开jQuery插件属性 [英] exposing jQuery plugin properties

查看:113
本文介绍了公开jQuery插件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下JQuery插件.是否可以将变量'elements'公开给插件外部的javascript?如果是这样,这是怎么做的?对于此插件外部的javascript,访问元素"的语法是什么?

Given the following JQuery plugin. Is it possible to expose the variable 'elements' to javascript external to the plugin? And if so, how is this done? For javascript external to this plugin, what would the syntax be to access 'elements'?

(function($) {
    $.fn.myPlugin = function() {

        // I WANT TO EXPOSE THIS AS A 'PUBLIC' PROPERTY OF THIS PLUGIN
        var elements = {};

        return this;
    };
})(jQuery);

$('.selector').myPlugin();
​

推荐答案

(function($) {
   $.myPlugin = {
       elements: {}
   };

    $.fn.myPlugin = function() {
        return this;
    };
})(jQuery);

这篇关于公开jQuery插件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆