![](/img/trans.png)
[英]jQuery Plugin Development - passing parameters to user defined callback function
[英]jQuery plugin callback function parameters
我正在尋找一種更好的方法來訪問/管理插件回調函數中的數據。 我想做與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});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.