usmaps.js事件绑定

时间:2015-04-23 14:26:06

标签: javascript jquery json

我想弄清楚这段代码,但我不能。我曾多次尝试破译这个。有人可以帮助我。

System.gc()

我希望这是一个点击事件。

2 个答案:

答案 0 :(得分:1)

文件显示:

$('#map').usmap({
  // The click action
  click: function(event, data) {
    $('#clicked-state')
      .text('You clicked: '+data.name)
      .parent().effect('highlight', {color: '#C7F464'}, 2000);
  }
});

你尝试过这样吗?

修改

$('#map').usmap({
  clickState: {
    'NY' : function(event, data) {
      console.log('You interacted with the state of Maryland');
    }
  }
});

这样您就可以只点击一个州。

答案 1 :(得分:0)

我最终完成了这样的

click: function(event, data) {
        if(data.name == "AK" || data.name == "AL" || data.name == "OR" || data.name == "CO" || data.name == "WA"){
            $('#clicked-state').text("Marijuana is legalized for recreational use for those over the age of 21 in " + data.name);
        }
        else if(data.name == "CA" || data.name == "NV" || data.name == "MT" || data.name == "AZ" || data.name == "MN" || data.name == "IL" || data.name == "MI" || data.name == "NY" || data.name == "VT" || data.name == "NH" || data.name == "ME" || data.name == "MA" || data.name == "CT" || data.name == "NJ" || data.name == "MD" || data.name == "DE" || data.name == "RI" || data.name == "DC"){
            $('#clicked-state').text("Medical marijuana is legalized in " + data.name);
        }
        else{
            $('#clicked-state').text("Marijuana is illegal in " + data.name);
        }
    }