[英]Calling custom jQuery plugin inside other jQuery plugin
I am using Twitter Bootstrap's .popover
jQuery plugin. 我正在使用Twitter Bootstrap的
.popover
jQuery插件。 I am writing my own jQuery plugin that utilizes .popover
, but the console says that this
"has no method 'popover'." 我正在编写自己的jQuery插件,它使用
.popover
,但控制台说this
“没有方法'popover'。” Here's my code: 这是我的代码:
$.fn.mypopover = function(msg){
this.click(function(){
this.popover({title:"Static title",content:msg,trigger:'manual'}).popover('show');
});
}
Inside the $.fn.popover
function, this
is the jQuery object that popover()
was called on. 在
$.fn.popover
函数内部, this
是$.fn.popover
popover()
的jQuery对象。 However, inside the callback to this.click()
, this
is the element that triggered the click event. 但是,在
this.click()
的回调中, this
是触发click事件的元素。 Every time you are inside another function
, this
will be different (based on how the function is called). 每次进入另一个
function
, this
将是不同的(基于函数的调用方式)。
You need to do $(this).popover()
inside the click event. 你需要在click事件中做
$(this).popover()
。
$.fn.mypopover = function(msg){
// "this" is a jQuery object
this.click(function(){
// "this" is a DOM element
$(this).popover({title:"Static title",content:msg,trigger:'manual'}).popover('show');
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.