【问题标题】:Grabbing PHP info and placing inside divs获取 PHP 信息并放置在 div 中
【发布时间】:2011-08-16 16:40:23
【问题描述】:

我不确定这是否可行,但我正在尝试获取 $css_color 的值并将其设置为 div 中的十六进制值。还有 $x 和 $y 值。

本质上,我正在尝试从图像中获取 $x$y 信息和十六进制代码值,并将其与我在 formatted_colors.js 中的颜色值数组进行匹配,然后将“图像”重建为 div背景颜色作为测试。

我的 formatted_colors.js 数组示例var colors = []; colors["000000"] = "black"; colors["100000"] = "black";

这是一个sn-p:

<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

<div class="rounded_color" hex="<?php $css_color ?>" xy="<?php $x.$y ?>"</div>
<div id="<?php $x.$y ?>"></div>

$(document).ready(function() {

    $(".rounded_color").each(function(){
            var google_color = getColor($(this).attr("hex"));
            $('#'+$(this).attr("id")).html(google_color);
            $('#'+$(this).attr("id")).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/A4tMsn2C

【问题讨论】:

    标签: php javascript jquery html syntax


    【解决方案1】:

    改用&lt;?php echo $x.$y ?&gt;(其他块也类似)。或者,如果您启用了短标签 &lt;?= $x . $y ?&gt;。您的版本只是进行连接并丢弃结果。您需要在 PHP 块中回显您正在执行的任何操作的结果。

    【讨论】:

    猜你喜欢
    • 2014-05-12
    • 2015-08-12
    • 2017-01-12
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    相关资源
    最近更新 更多