如何在jquery中使用带有事件ui的命名函数
我有这个功能:如何在jquery中使用带有事件ui的命名函数,jquery,Jquery,我有这个功能: $( ".timebox" ).draggable({ containment: "parent", axis: "x" , drag: refactorTimebox(event, ui) }); function refactorTimebox(event, ui){ console.log(ui.position); } 我想调用函数refactorTimebox(event,ui)。如何将事件和ui变量传递给函数 行拖动
$( ".timebox" ).draggable({
containment: "parent",
axis: "x" ,
drag: refactorTimebox(event, ui)
});
function refactorTimebox(event, ui){
console.log(ui.position);
}
我想调用函数refactorTimebox(event,ui)
。如何将事件
和ui
变量传递给函数
行拖动:refactorTimebox(事件,ui)
不起作用
这是重构TimeBox函数:
$( ".timebox" ).draggable({
containment: "parent",
axis: "x" ,
drag: refactorTimebox(event, ui)
});
function refactorTimebox(event, ui){
console.log(ui.position);
}
您只需要传递对函数的引用,而不需要调用它。只需按名称传递即可
$( ".timebox" ).draggable({
containment: "parent",
axis: "x" ,
drag: refactorTimebox
});
插件将使用参数调用它,只需写函数名而不写方法签名
$( ".timebox" ).draggable({
containment: "parent",
axis: "x" ,
drag: refactorTimebox
});