我在一页上有 50 个点,每个单独的 div。当我单击一个时,我想使用 ID 从数组中提取值。我可以获得 ID,但我无法使用该值从我的数组中取出东西。也许是全局变量问题?没有把握。甚至不确定这是否是处理访问多个数据的多次点击的最佳方式。任何帮助表示赞赏!
var location0 = {"name" : "Location 1", "image" : "image1.jpg"};
$('.dot').click(function(){
var thisLocation = $(this).attr("id");
alert(thisLocation); //Returns "location0"
alert(thisLocation["image"]); //Returns "undefined"
});