編輯,這種解決問題的每個jQuery中的每一個?
要我好象我們需要循環3次這樣的代碼使用數組,感謝亞歷山大
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","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>";
});
是的,我想知道是否有一個jQuery解決方案還:-) – Pluda 2011-05-27 16:03:04