gpt4 book ai didi

javascript - 关于数组不起作用的思考

转载 作者:行者123 更新时间:2023-12-03 10:20:26 24 4
gpt4 key购买 nike

我正在项目页面上的链接上切换类,并且当仅使用单个 id 时,类更改似乎有效,但是当使用数组“myArray”时,没有任何反应。好奇是否有人有任何想法为什么。这是我正在使用的代码:

var oldpage = $("#oldpage");
var phpscript = $("#phpscript");
var db = $("#db");
var nypl = $("#nypl");
var ppt = $("#ppt");
var myArray = [nypl, db, ppt, phpscript, oldpage];
$(function() {
var classes = ["paris", "chateau", "violin", "create", "museum"];
var id = $(myArray);
var count = 0;

function nextClass() {
id.addClass(classes[count = ++count % classes.length]);
id.removeClass(classes[count = ++count % classes.length]);
setTimeout(nextClass, 300);
}
setTimeout(nextClass, 300);
id.addClass(classes[0]);
id.removeClass(classes[0]);
console.log(id);
});
.paris {
color: pink;
}
.violin {
color: rgb(134, 134, 134);
}
.museum {
color: red;
}
.create {
color: orange;
}
.chateau {
color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="projects">
<li><a href="http://web.simmons.edu/~duffp/lis489/indexver1.html" target="new" class="violin" id="oldpage">First iteration of this page</a>
</li>
<br />
<li><a href="http://web.simmons.edu/~duffp/lis489/php/contactme.txt" target="new" id="phpscript" class="violin">PHP Mail script attached below.</a>
</li>
<br />
<li><a href="http://web.simmons.edu/~duffp/lis489/Dufflibrary.php" target="new" id="db" class="violin">Searchable Database (In progress)</a>
</li>
<br />
<li><a href="http://web.simmons.edu/~duffp/lis403/Duff_Song_Usability_ppt.ppt" target="new" id="nypl" class="violin">NYPL Usability Testing</a>
</li>
<br />
<li><a href="http://web.simmons.edu/~duffp/lis403/Duff_Krim_Song_Evaluation_ppt.ppt" target="new" id="ppt" class="violin">Evaluation of Online Services</a>
</li>
</ul>
</div>

最佳答案

试试这个:

function nextClass() {
for (var i = 0; i < myArr.length; i++) {
myArr[i].addClass(classes[count = ++count % classes.length]);
myArr[i].removeClass(classes[count = ++count % classes.length]);
setTimeout(nextClass, 300);
}
}

关于javascript - 关于数组不起作用的思考,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29660800/

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