【发布时间】:2016-03-10 03:56:27
【问题描述】:
我根据此处生成的代码创建了一个基本插件模板: http://starter.pixelgraphics.us/
这是一个非常基本的骨架的链接: https://jsbin.com/yatofefade/edit?html,js,console,output
$.curationPanel = function( el, options ) {
var base = this;
base.$el = $(el);
base.el = el;
base.$el.data( "curationPanel", base );
base.init = function( ) {
base.options =
$.extend( {}, $.curationPanel.defaultOptions, options );
};
base.runMe = function( ) {
alert( "I've Been Run" );
};
base.init( );
};
$.curationPanel.defaultOptions = { };
$.fn.curationPanel = function( options ) {
return this.each( function( ) {
(new $.curationPanel( this, options ));
});
};
$(".curationPanel").each( function( i, val ) {
var cp = $(this).curationPanel({});
cp.runMe( );
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="curationPanel">INSIDE THE PANEL<div class="curationErrors"></div></div>
</body>
</html>
我的问题是,为什么在创建的 curationPanel 实例上尝试调用 runMe() 时会出错?在插件中创建可调用公共函数的正确方法是什么?
【问题讨论】:
-
你需要在这里分享你的代码......不仅仅是一个链接
-
好的,更新了...谢谢。
标签: javascript jquery html object jquery-plugins