我无法提醒与区域标签 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"}
]
};
我通过调用 json
<script src="json_states.json" type="text/javascript"> </script>
我究竟做错了什么?