【发布时间】:2012-10-16 15:52:15
【问题描述】:
如何从同一个对象内部调用 jQuery 插件的函数。我使用确切的建议解决方案http://docs.jquery.com/Plugins/Authoring#Plugin_Methods。从外部代码我可以这样调用:
$('div').tooltip("myMethod", an_attr);
但是当'this'不是插件的对象时,我如何从内部调用相同的事件,尤其是表单事件。
var methods = {
var $this = $(this);
init : function( options ) {
$this.click(function(){
$this.fn2("myMethod", an_attr); //is it right way?
});
},
fn2 : function() {
//but how can I call the myMethod. here ?
},
myMethod : function() {...
【问题讨论】:
-
你不需要将
this包裹在$()中,它已经是一个jQuery对象了。 -
您能否详细说明
this应该是什么以及您想调用什么,按什么顺序?
标签: jquery jquery-plugins call