Javascript 我能';t访问jquery插件方法的调用者
我有一个jQuery插件,如下所示:Javascript 我能';t访问jquery插件方法的调用者,javascript,jquery,Javascript,Jquery,我有一个jQuery插件,如下所示: (函数(e){ e、 fn.dmHall=函数(args){ var st={ 推:30, rtl:错, }; e、 扩展(st,args); var main=e(本); e、 fn.dmHall.hideThis()=函数(args){ this.hide(); } $('#myelement')。单击(函数(e){ $(this.dmHall.hideThis(); }); } })(jQuery) 但是,这不起作用,如果不将其设置为参数,我无法将$
(函数(e){
e、 fn.dmHall=函数(args){
var st={
推:30,
rtl:错,
};
e、 扩展(st,args);
var main=e(本);
e、 fn.dmHall.hideThis()=函数(args){
this.hide();
}
$('#myelement')。单击(函数(e){
$(this.dmHall.hideThis();
});
}
})(jQuery)
但是,这不起作用,如果不将其设置为参数,我无法将$(“#myelement”)
作为hideThis()
方法的调用方
我想创建一个子方法,它可以像
hide()
或任何东西一样工作。此代码用于插件文件dmhallthide
jQuery插件列表中添加了新函数:
(function(e, window, document, undefined) {
e.fn.dmHallThisHide = function (args) {
var st = {
push: 30,
rtl: false,
};
e.extend(st, args);
var main = e(this);
this.each(function(index, value) {//this.each is required as selector may get element array
e(this).hide();
});
}
})(jQuery, window, document);
要调用此插件,需要以下代码(可以在单独的文件中):
$(文档).ready(函数(){
$().dmHallThisHide();
});
请查看jQuery插件样板文件,了解jQuery插件的更详细版本,链接:为什么不使用hide()
?我看不到仅仅为一个方法调用使用包装器的好处。
$(document).ready(function() {
$(<<SELECTOR>>).dmHallThisHide();
});