我已经创建了基于这里生成的代码基本插件模板: http://starter.pixelgraphics.us/调用成员函数中
这里是一个链接到非常基本骨架: https://jsbin.com/yatofefade/edit?html,js,console,output
$.curationPanel = function(el, options) {
\t var base = this;
\t base.$el = $(el);
\t base.el = el;
\t \t \t
\t base.$el.data("curationPanel", base);
\t \t \t
\t base.init = function() {
\t base.options =
$.extend({}, $.curationPanel.defaultOptions, options);
\t };
\t \t \t
\t base.runMe = function() {
\t \t alert("I've Been Run");
\t };
\t \t \t
\t base.init();
\t \t \t
};
\t \t
$.curationPanel.defaultOptions = { };
\t \t
$.fn.curationPanel = function(options) {
\t return this.each(function() {
\t \t (new $.curationPanel(this, options));
\t });
};
$(".curationPanel").each(function(i, val) {
\t var cp = $(this).curationPanel({});
\t 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()时出现错误?在插件中创建可调用公用函数的正确方法是什么?
你需要在这里分享你的代码.. 。不只是一个链接 –
好的,更新... thx。 –