调用在var中分配的url

时间:2012-08-07 11:20:59

标签: javascript map svg raphael

在玩Raphael.js Australia map时,我尝试通过在路径末尾更改其属性来为每个元素分配网址:

country.cityone = R.path("coordinates").attr({href: "cityone.html"}).attr(attr);
country.citytwo = R.path("coordinates").attr({href: "citytwo.html"}).attr(attr);
...

以上适用于Firefox,Chrome等,但IE6-IE9在声明方面存在问题。

所以我想在var country之后声明另一个变量并将URL分配给它:

var url = {};
url.cityone = "cityone.html";
url.citytwo = "citytwo.html";

然后在鼠标点击/按下时调用它:

    st[0].onmousedown = function() {

    current && country[current] && document.getElementById(“current”).appendChild(url);

    };

然而它根本不起作用。显然,我没有正确地通过该功能拨打电话,将每个URL与其各自的城市相关联。我错过了什么?

2 个答案:

答案 0 :(得分:1)

我没有测试过这个,但我很确定你应该取消href并添加一个鼠标事件:

country.cityone = R.path("coordinates").attr(attr).click(function(){
  window.location.href = "cityone.html";
});

我很确定这会奏效。

答案 1 :(得分:1)

关闭这个问题,经过几次试验,我最终发现IE需要双击click(function(){才能打开href页面

我在上面的代码中发现:

country.cityone = R.path("coordinates").attr(attr).click(function(){
  window.location.href = "cityone.html";
});

我必须将.click(function(){更改为.mousedown(function(){以使IE正常工作。

谢谢@Zevan! 干杯