问题描述
|
编辑,这解决了问题
要像我一样使用数组,我们需要像这样的代码循环3次,谢谢Alexander
var str = \'\';
$.each(cores,function(i,value) {
$.each(value,function(j,value_2) {
$.each(value_2,function(k,sel_cor) {
console.log(sel_cor);
str += \"<div class=\'cores\' title=\"+sel_cor+\" style=\'background-color:#\"+sel_cor+\"\'></div>\";
});
});
});
我正在尝试制作一个jQuery配色器。
我有3个具有十六进制颜色的数组,并且我想为每个数组建立一个正方形,因此我需要为每个数组的每个子数组。
这可能吗?如何才能做到这一点?
cores[0] = [[\"e3e3e7\",\"e5e5e6\",\"ecdfec\",\"e6dfec\",\"dfdfe6\",\"dfe6e6\",\"dfe6df\",\"e8e8e0\",\"f9f2df\",\"f4e9df\",\"ecdfdf\",\"e5e4e2\"]];
cores[1] = [[\"e3e3e7\",\"e5e4e2\"]];
cores[2] = [[\"e3e3e7\",\"e5e4e2\"]];
$.each(cores,value) {
console.log(\'j = \'+j+\' value = \'+value);
str_claras += \"<div class=\'tile\' style=\'width:20px; height:20px; padding:0;margin:0;border:1px solid #333333;cursor:pointer;background-color:#\"+j[value]+\"\'></div>\";
});
解决方法
您不能只使用javascript的内置for循环结构吗?
for(core in cores)
{
for(blah in blahs)
{
//...
}
}
, $.each(cores,function(j,value) {
$.each(value,function(i,value2) {
str_claras += \"<div class=\'tile\' style=\'width:20px; height:20px; padding:0;margin:0;border:1px solid #333333;cursor:pointer;background-color:#\"+value2+\"\'></div>\";
});
});
这里是链接:单击此处