gpt4 book ai didi

Jquery - 避免代码重复

转载 作者:行者123 更新时间:2023-12-01 02:19:55 25 4
gpt4 key购买 nike

我只是想知道是否可以简化这种代码:

$(this).formWizard( {
onNext: function(tab, navigation, index) {
## My code
},
onLast: function(tab, navigation, index) {
## My code
},
...
})

像这样或者其他:

$(this).formWizard( {
onNext, onLast: function(tab, navigation, index) {
## My code
}
})

我知道还有其他解决方案,但是有没有办法将多个事件分组到一个函数中?

抱歉我的英语不好。感谢您的帮助。

最佳答案

为什么不将函数保存到变量中?

var myHandler = function(tab, navigation, index) {
// My code
};

$(this).formWizard( {
onNext: myHandler,
onLast: myHandler
})

关于Jquery - 避免代码重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25652151/

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