Значения не отображаются и не отображаются на странице. Он должен создавать div, которые всплывают с google_color
, а фон установлен в шестнадцатеричное значение.
Предполагается, что приложение берет пиксельные данные изображения и сопоставляет их с моей библиотекой образцов, известной как formatted_colors.js, которая является массивом. Массив выглядит так:
var colors = [];
colors["000000"] = "black"; colors["100000"] = "black"; colors["200000"] = "black";
Может быть, я не предполагаю использовать функцию .each? Хотя это и есть петля.
Вот фрагмент:
<div class="rounded_color" hex="<?php echo $css_color ?>" xy="<?php echo $x.$y ?>"></div>
<div id="<?php echo $x.$y ?>"></div>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script src="formatted_colors.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
//iterate through pixels and match rounded color to array in formatted_colors.js
$(document).ready(function() {
$(".rounded_color").each(function(){
var google_color = getColor($(this).attr("hex")); // finds a match of "hex" value in formatted_colors.js and return name to google_color
$('#'+$(this).attr("hex")).html(google_color); // set the div's html to name which is google_color
alert('#'+$(this).attr("id")); //testing if value is there, but shows #undefined
$('#'+$(this).attr("hex")).css('background-color:', google_color);
})
// get name of color function from formatted_colors.js
function getColor(target_color){
if (colors[target_color] == undefined) { // not found
return "no match";
} else {
return colors[target_color];
}
} // end getColor function
}) // end ready function
</script>
Извините, я новичок в этом, поэтому я не уверен, что именно делать сейчас.
Вот весь мой код: http://pastebin.com/HEB3TWZP
Заранее спасибо!