gpt4 book ai didi

jquery - 将以下三元运算符转换为常规 if 语句?

转载 作者:行者123 更新时间:2023-12-01 08:09:53 24 4
gpt4 key购买 nike

我是网络编程新手,对三元运算符处理得不多。我找到了一些 jquery slider 的示例代码,但我需要编辑它,以便当用户将鼠标移到横幅上时它会停止。我希望有人可以帮助我将下面的代码转换成我更习惯处理的一组简单的 if 和 else if 语句。提前致谢。

//Get next image, when it reaches the end, rotate it back to the first image 

var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));

最佳答案

不使用三元运算符的等效项是:

var next;
if (current.next().length) {
if (current.next().hasClass('show')) {
next = $('div.rotator ul li:first')
}
else {
next = current.next();
}
}
else {
next = $('div.rotator ul li:first'));
}

关于jquery - 将以下三元运算符转换为常规 if 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14325159/

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