如何从插件外部在插件内部运行jquery函数?
例如,如何在下面的样例书函数中运行“.\u openclose()” 我试过这样的东西:如何从插件外部在插件内部运行jquery函数?,jquery,jquery-plugins,Jquery,Jquery Plugins,例如,如何在下面的样例书函数中运行“.\u openclose()” 我试过这样的东西: $( '#sb-container' ).swatchbook = function () { this._openclose() } 关于这个插件的文档中有很多有用的信息。jQuery的内容位于底部 在没有使用插件的情况下,我不确定它到底是如何工作的,但我可以马上看出您的“this”不是jQuery对象。尝试: $( '#sb-container' ).swatchbook = functio
$( '#sb-container' ).swatchbook = function () {
this._openclose()
}
关于这个插件的文档中有很多有用的信息。jQuery的内容位于底部 在没有使用插件的情况下,我不确定它到底是如何工作的,但我可以马上看出您的“this”不是jQuery对象。尝试:
$( '#sb-container' ).swatchbook = function () {
$(this)._openclose()
});
或
_self在插件中声明为变量“this”:
var _self = this;
您可以根据
closeIdx:11
行的指定触发项上的事件
$(function() {
$( '#sb-container' ).swatchbook( {
// number of degrees that is between each item
angleInc : 15,
neighbor : 15,
// if it should be closed by default
initclosed : true,
// index of the element that when clicked, triggers the open/close function
// by default there is no such element
closeIdx : 11
} );
});
function test(){
$('.sb-toggle').trigger('click');
}
HTML:
<div id="test" onclick="test();">Test</div>
测试
我试图让它在没有内部切换链接的情况下工作,只有外部切换链接
<div id="test" onclick="test();">Test</div>