이 함수는 요소를 클릭 할 때 호출됩니다. 클릭 한 요소를 기반으로 문자열을 만든 다음 JSON 객체에서 해당 문자열과 연결된 값을 조회합니다. 그런 다음 그 값을 경고합니다. 여기 보이는 방법은 다음과 같습니다 내가 찾은 무엇JSON 객체가있는 JavaScript 범위
function alertHelp(){
var option = $(this).context.parentNode.textContent.substring(0, $(this).context.parentNode.textContent.length - 2);
$.getJSON("Messages.json", function(json, option) {
alert(json[option]);
});
}
는 경고를 변경하여 함수에 전달 될 때 해당 옵션은 다음 올바르게 설정되어 있지만입니다. alert(json[object]);
앞에 내가 alert(option)
이라면 간단히 "성공"이라고 경고합니다. 그게 뭔지 잘 모르겠다. alert(json[option])
은 단순히 "정의되지 않음"을 경고합니다.
function
인수
option
하여
var option
"그림자"한
{
"Space Control": "Red = a square black controls. Green = a square white controls. Yellow = a square contested by both players",
"Legal Moves": "Click on a piece and a blue dot will appear on all the squares that piece can move to",
"PieceFlair": "When you move a piece, all the pieces that come under attack as a direct result of the piece you moved will pulse white",
"Forks": "All the moves that would result in a simultaneous attack of two pieces are shown",
"Pins": "Not yet implemented"
}
당신은 Messages.json의 내용을 게시 할 수 있습니까? JSON의 구조가 무엇이 진행되고 있는지 이해하는 것이 유용 할 것입니다. –
문제 없습니다. 완료 및 완료. –
'alert (option);가 "success"를 표시하는 이유는 콜백에 대한 두 번째 매개 변수로 재정의했기 때문입니다 :', function (json, option) {'. 어느 쪽이든 포함시키지 마십시오 (필자가 필요하다고 생각하지 않기 때문에) 또는 매개 변수 이름을 변경하십시오 – Ian