我無法警告對應於區域標記ID的對象值。與輸入值相關的對象的警報值屬性
我的代碼,
$(document).ready(function() {
$(".wholecirclewrapper area").click(function(){
if($(this).hasClass("active")) {
return false;
}
var choice = $(this).attr("id");
$.each(results.States, function(i, item) {
var st=results.States[i].Name;
if(choice==st)
{
alert(results.States[i].ISHI);
}
});
});
});
我的HTML代碼
<div id="mapdiv">
<img src="india.gif" alt="India" usemap="#indiamap" />
<map name="indiamap" class="wholecirclewrapper">
<area class="specificshelfdiv1" id="AndraPradesh" shape="rect" coords="0,0,82,126" href="#" />
<area class="specificshelfdiv2" id="ArunachalPradesh" shape="circle" coords="90,58,3" href="#" />
<area class="specificshelfdiv3" id="Assam" shape="circle" coords="124,58,8" href="#" />
</map>
</div>
我的外部JSON看起來像
var results={"States":[
{ "Name" : "AndraPradesh" , "ISHI" : "19.5 (Serious)" ,"Literacy rate" : "67.7" ,"Population rate" : "84,665,533" ,"NFHS" : "29.8" ,"Tap water" : "69.9"},
{ "Name" : "ArunachalPradesh" , "ISHI" : "Not estimated" ,"Literacy rate" : "67" ,"Population rate" : "1,382,611" ,"NFHS" : "29.6" ,"Tap water" : "65.5"},
{ "Name" : "Assam" , "ISHI" : "19.8 (Serious)" ,"Literacy rate" : "73.2" ,"Population rate" : "31,169,272" ,"NFHS" : "35.8" ,"Tap water" : "10.5"}
]
};
我正在通過
<script src="json_states.json" type="text/javascript"> </script>
調用JSON
我做錯了什麼?
這不是JSON,這是一個JavaScript對象。 – 2012-08-15 12:02:16
做一些基本的調試。檢查'choice'和'results.States [i] .Name'是什麼。 – 2012-08-15 12:04:53
我跑了腳本,它爲我工作,我認爲**結果**沒有正確定義在您的示例 – Valentin 2012-08-15 12:06:41