값이 페이지에 나타나지 않고 나타나지 않는 것 같습니다. 그것은 google_color
및 16 진수 값으로 설정된 배경으로 팝업되는 div를 생성해야합니다.jQuery가 변수 정보를 얻지 못하는 이유를 잘 모름
이 응용 프로그램은 픽셀 이미지 데이터를 받아 배열 인 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감사 :
여기 내 전체 코드입니다!
formatted_colors.js에서 colors 배열을 어디에 설정합니까? $ (document) .ready() 함수 안에이 파일을 설정하면이 파일에서 액세스하려고 할 때 변수의 범위에 문제가 있다는 것입니다. 또한, 배경색을 .css()로 설정할 때 콜론이 필요하다고 생각하지 않습니다. – Compeek