Php 不知道为什么jQuery不是';无法获取可变信息

Php 不知道为什么jQuery不是';无法获取可变信息,php,javascript,jquery,syntax,Php,Javascript,Jquery,Syntax,这些值似乎没有显示在页面上。它应该创建带有google_color和设置为十六进制值的背景弹出的div 该应用程序将获取像素图像数据,并将其与我的样本库formatted_colors.js匹配,该样本库是一个数组。该数组如下所示: var colors=[]; 颜色[“000000”]=“黑色”;颜色[“100000”]=“黑色”;颜色[“200000”]=“黑色” 也许我不应该使用。每个函数?虽然这是一个循环 以下是一个片段: <div class="rounded_color" he

这些值似乎没有显示在页面上。它应该创建带有
google_color
和设置为十六进制值的背景弹出的div

该应用程序将获取像素图像数据,并将其与我的样本库formatted_colors.js匹配,该样本库是一个数组。该数组如下所示:

var colors=[];
颜色[“000000”]=“黑色”;颜色[“100000”]=“黑色”;颜色[“200000”]=“黑色”

也许我不应该使用。每个函数?虽然这是一个循环

以下是一个片段:

<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>

您不需要连接
#
<代码>此
是迭代中的当前元素


另外,您可能需要执行类似于
var$this=$(this)的操作清理代码,而不是在同一次迭代中一次又一次地重新创建jQuery对象

您不需要连接
#
<代码>此
是迭代中的当前元素


另外,您可能需要执行类似于
var$this=$(this)的操作清理代码,而不是在同一次迭代中一次又一次地重新创建jQuery对象

在格式化的_colors.js中,您在哪里设置颜色数组?如果您在$(document).ready()函数中设置它,那么我猜您在试图访问此文件中的变量时,变量的范围有问题。另外,我认为在使用.css()设置背景色时不需要冒号。在格式化的_colors.js中,您在哪里设置颜色数组?如果您在$(document).ready()函数中设置它,那么我猜您在试图访问此文件中的变量时,变量的范围有问题。另外,我认为在使用.css()设置背景色时不需要冒号。