【发布时间】:2015-11-29 16:20:58
【问题描述】:
我有这个数组:
var conditions = [];
conditions [0] = ["0", "1", "2", "3", "4"];
conditions [1] = ["5", "6", "7", "8", "9"];
conditions [2] = ["19", "20", "21", "22"];
conditions [3] = ["13", "14", "15", "16"];
我要做的是循环遍历数组,这样当 weather.code 值(使用 jQuery 检索)满足数组中的值时,背景颜色会相应改变。 if 语句不完整,这只是向您展示我的意思的示例:
if(weather.code === **item in conditions[1] for example**) {
$("#page").css({background: "#F7AC57"}, 1500);
}
else {
$('#page').css({background: "#000"}, 1500);
}
任何关于我如何实现这一目标的建议都将不胜感激。我是 JavaScript/jQuery 新手。
【问题讨论】:
-
你正在寻找数组原型 indexOf() 方法:developer.mozilla.org/en/docs/Web/JavaScript/Reference/…
标签: javascript jquery arrays loops