gpt4 book ai didi

javascript - 如何通过 start : stop: while using the parameters 'ev' and 'ui' ? 使用我自己的函数

转载 作者:行者123 更新时间:2023-11-28 13:45:54 24 4
gpt4 key购买 nike

在我的可拖动对象中,start:stop: 处的代码变得太大(50-100 行),我开始出现可读性问题。

$(".dra").draggable({
revert: "invalid",
start: function(ev, ui){
//...50-100 lines...
},
stop: function(ev, ui){
//...50-100 lines...
}
});

为了提高可读性,我想创建两个全局函数 startDrag()stopDrag() 并像 start: startDrag(ev,用户界面)。但我未能成功完成这项工作:

function startDrag(ev, ui){
//...50-100 lines...
}

function stopDrag(ev, ui){
//...50-100 lines...
}

function createDraggables(){
$(".dra").draggable({
revert: "invalid",
start: startDrag(ev, ui),
stop: stopDrag(ev, ui)
});
}

有什么想法为什么这不起作用吗?

最佳答案

尝试将其更改为:

function createDraggables(){
$(".dra").draggable({
revert: "invalid",
start: startDrag,
stop: stopDrag
});
}

关于javascript - 如何通过 start : stop: while using the parameters 'ev' and 'ui' ? 使用我自己的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14444060/

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