【发布时间】:2011-08-09 04:21:24
【问题描述】:
我正在尝试将 ID(即 html 跨度中的 $hexcode 值)添加到数组中。我如何用 jQuery 做到这一点?最终,我将需要获取这些十六进制代码值并将它们与颜色索引匹配。
<?php
// display every color in the world
$r = 0;
$g = 0;
$b = 0;
$i = 0;
$step = 16;
for($b = 0; $b < 255; $b+=$step ) {
for($g = 0; $g < 255; $g+=$step) {
for($r = 0; $r < 255; $r+=$step) {
$hexcolor = str_pad(dechex($r), 2, "0", STR_PAD_LEFT).str_pad(dechex($g), 2, "0", STR_PAD_LEFT).str_pad(dechex($b), 2, "0", STR_PAD_LEFT);
echo '<span class="color_cell" id="'.$hexcolor.'" style="width: 5px; height: 5px; background-color:#'.$hexcolor.'; border: 1px dotted;"> </span>'
if($i%256 == 0) {
echo "<br />";
}
$i++;
}
}
}
?>
<script src="jquery-1.6.2.js"></script>
<script type="text/javascript">
var ids = [];
$(document).ready(function($) {
$(".color_cell").bind('click', function() {
alert('Test');
//how do i add the ID (which is the $hexcolor into this array ids[]?
ids.push($(this).attr('id'));
});
});
提前致谢!
【问题讨论】:
-
对我来说没问题。什么不工作?
-
您遇到了什么问题?什么不工作?
标签: javascript jquery arrays