gpt4 book ai didi

javascript - jQuery 插件回调函数参数

转载 作者:行者123 更新时间:2023-11-29 18:19:12 24 4
gpt4 key购买 nike

我正在寻找一种更好的方法来访问/管理插件回调函数中的数据。我想做与 jQuery UI 相同的事情。

UI 示例:(我想怎么做)http://api.jqueryui.com/sortable/

$( ".selector" ).sortable({
activate: function( event, ui ) {
alert(ui.item)
alert(ui.position)
alert(ui.offset)
}
});

我的插件示例(我现在如何拥有它):

$( ".selector" ).myplugin({
activate: function( event, item, postion, offset ) {//to much parameters
alert(item)
alert(position)
alert(offset)
}
});

//inside the plugin
var varItem = '';
var varPosition = '';
var varOffset = '';

if(typeof self.o.activate == 'function'){
self.o.activate.call(this, varItem, varPosition, varOffset);
}

最佳答案

这应该可以解决问题

$( ".selector" ).myplugin({
activate: function( event, object ) {//to much parameters
alert(object.item)
alert(object.position)
alert(object.offset)
}
});

//inside the plugin
var varItem = '';
var varPosition = '';
var varOffset = '';

if(typeof self.o.activate == 'function'){
self.o.activate.call(this, {item: varItem, position: varPosition, offset: varOffset});
}

关于javascript - jQuery 插件回调函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20435927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com