2

我有一张使用拉斐尔绘制的美国各州和县的地图。此外,每条路径都有一个mouseovermouseout事件绑定到它。每个路径作为一个 FIPS ID 号作为元素 ID

我还有一个 jQuery 自动完成文本输入框。根据建议下拉列表中keyupkeydown事件,我想触发关联的路径 IDmouseover事件处理程序。

给定由以下人员绘制的地图:

function drawMap(data) {
  map = Raphael(document.getElementById("us_map_container", 555, 352));
  var pathCount = data.length;

  for (i = 0; i < pathCount; i++) {
    var currentPath = map.path(data[i][2]),
    pid = data[i][1],
    pname = data[i][0];

    currentPath.node.setAttribute("id", pid);
    currentPath.node.setAttribute("name", pname);
    currentPath.attr({"stroke" : "#FFFFFF", "fill" : "#CBCBCB", "stroke-width" : "0.2"});

    currentPath.mouseover(function(e){countyMouseOver(e)});
    currentPath.mouseout(function(e){countyMouseOut(e)});
  }
}

和相关的mouseover事件:

function countyMouseOver(e) {
    var hover = e.target;
    var name = hover.getAttribute("name");
    if (name != "#State_borders") {
        $(hover).attr({"stroke" : "#FF0000", "stroke-width" : "1", "fill" : "#FF0000"});
        console.log("Name: " + name + "  ID: " + hover.id);
    }
}

如何使用此keypress侦听器执行触发事件?

$("#county_search_autocomplete").keypress(function(e) {
    if (e.which == 13){
        var index = $.inArray($(this).val(), counties)
        if (index > 0){
            console.log("FIPS: " + counties[i].id);
        }
    }

    else if (e.which == 38 || e.which == 40){
         //trigger Raphael mouseover event... how?
    }
});
4

0 回答 0