我有一個對象叫Breadcrumb
,它有一個函數expandEllipses
。以下工作正常:在JQuery事件處理程序中調用原型對象方法
mbc = jQuery('#breadcrumb').breadcrumb({
items : initItems
});
jQuery("body").on("click", ".breadcrumb .breadcrumbEllipses", function(e) {
mbc.expandEllipses();
});
不過,我不知道怎麼跟我這樣做是一個jQuery的事件處理程序,我沒有目標就在那裏:
jQuery("body").on("click", ".breadcrumb .breadcrumbEllipses", function(e) {
parObj = <parent of the .breadcrumbEllipses instance that triggered this event>
protoObj = <Prototype object from parentObj>
protoObj.expandEllipses();
});
這是什麼最終從Barmar's回答工作:
jQuery.fn.breadcrumb = function(options) {
var bc = new Breadcrumb(this, options);
this.data('breadcrumb', bc);
return bc;
};
jQuery("body").on("click", ".breadcrumb .breadcrumbEllipses", function(e) {
bcObj = jQuery(this).closest(".breadcrumb").data("breadcrumb");
bcObj.expandEllipses();
});
'$(本).parent()'? – Downgoat