【发布时间】:2016-08-09 04:36:54
【问题描述】:
如果单击按钮,我想在数组中切换文本。
(text[0] -> text[1] -> text[2] -> text[0])
如果到达数组索引的末尾,则再次返回数组中索引的开始。(循环)
我认为使用 each 和 click 方法。 但每种方法都适用。
我该怎么做?
这是我的代码
$(document).ready(function() {
var arr = ["uno", "dos", "tre"];
$("button").click(fuction() {
$.each(arr, function() {
$("p").text(arr);
});
});
});
【问题讨论】:
-
如果您的答案已解决,请接受答案。
标签: jquery arrays indexing click each