我有一张使用Raphael绘制的美国州和县的地图。此外,每个路径都有一个mouseover和mouseout事件绑定到它。每个路径作为FIPS ID号作为元素ID
我还有一个jQuery自动完成文本输入框。在建议下拉列表中的keyup和keydown事件时,我想触发相关的路径ID鼠标悬停事件处理程序。
给出由
绘制的地图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)});
}
}
以及相关的鼠标悬停事件
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);
}
}
如何使用此按键侦听器执行触发事件?
$("#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?
}
});