每个内部都有jquery?

时间:2011-05-27 15:59:50

标签: jquery arrays

已编辑,这解决了问题

要像我这样使用数组,我们需要像这段代码一样循环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个十六进制颜色的数组,我想为每个数组构建litle square,所以我需要每个数组的每个数组。

这可能吗?怎么办呢?

cores[0] = [["e3e3e7","e5e5e6","ecdfec","e6dfec","dfdfe6","dfe6e6","dfe6df","e8e8e0","f9f2df","f4e9df","ecdfdf","e5e4e2"]];
cores[1] = [["e3e3e7","e5e5e6","ecdfec","e6dfec","dfdfe6","dfe6e6","dfe6df","e8e8e0","f9f2df","f4e9df","ecdfdf","e5e4e2"]];
cores[2] = [["e3e3e7","e5e5e6","ecdfec","e6dfec","dfdfe6","dfe6e6","dfe6df","e8e8e0","f9f2df","f4e9df","ecdfdf","e5e4e2"]];

$.each(cores, function(j, 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>";
    });

2 个答案:

答案 0 :(得分:2)

你不能只使用javascript的内置for循环结构吗?

for(core in cores)
{
   for(blah in blahs)
   {
      //...
   }
}

答案 1 :(得分:2)

    $.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>";
        });
 });

这是链接:Click Here