相关疑难解决方法(0)

使用jQuery插件设计模式调用方法

我一直在使用jQuery Boilerplate来开发插件,而我无法弄清楚的一件事是如何从插件外部调用方法.

作为参考,这里是我正在谈论的样板代码:http: //jqueryboilerplate.com/

在我的小提琴,

http://jsfiddle.net/D9JSQ/2/

这是代码:

;(function ( $, window, document, undefined ) {

    var pluginName = 'test';
    var defaults;

    function Plugin(element, options) {
        this.element = element;

        this.options = $.extend( {}, defaults, options) ;

        this._name = pluginName;

        this.init();
    }

    Plugin.prototype = {
        init: function() {
            this.hello();
        },
        hello : function() {
            document.write('hello');
        },
        goodbye : function() {
            document.write('goodbye');
        }
    }


    $.fn[pluginName] = function ( options ) {
            return this.each(function () {
                if (!$.data(this, 'plugin_' + pluginName)) { …
Run Code Online (Sandbox Code Playgroud)

jquery boilerplate

11
推荐指数
1
解决办法
5804
查看次数

标签 统计

boilerplate ×1

jquery ×1