Javascript Raphael Click处理程序未启动

Javascript Raphael Click处理程序未启动,javascript,click,raphael,Javascript,Click,Raphael,我以前也尝试过JQuery,它似乎也不起作用 我有emitterButton,它是Raphael中的一个圆,在函数中定义如下: emitterButton = canvas.circle(emitter_center_x,emitter_center_y,BUTTON_RADIUS) .attr({'fill':BUTTON_COLOR_UNPRESSED}) .attr({'id':'emitt

我以前也尝试过JQuery,它似乎也不起作用

我有emitterButton,它是Raphael中的一个圆,在函数中定义如下:

  emitterButton = canvas.circle(emitter_center_x,emitter_center_y,BUTTON_RADIUS)
                        .attr({'fill':BUTTON_COLOR_UNPRESSED})
                        .attr({'id':'emitterButton'});
。当我尝试附加单击处理程序时,通过

$(document).ready(function(){
  console.log("This is a hi!");
  console.log(emitterButton);
  emitterButton.click(function(){
    console.log("Hi!");
    if(emitterButton.attr('fill')==BUTTON_COLOR_UNPRESSED){
      console.log("Hi, again!");
      emitterButton.attr({'fill':BUTTON_COLOR_PRESSED});
    }
  });
});

前两个console.log语句启动,但后两个不启动。为什么我的点击功能不起作用

为什么说我以前也尝试过JQuery,而你仍然在使用JQuery?我以前使用了$'emitterButton',一个附加到emmiterButton的JQuery ID标记,而不是emitterButton行emitterButton中的emitterButton Raphael元素本身。单击函数{…}哦…确定。你们能做一把小提琴或类似的东西,这样我们可以看到更多正在发生的事情吗?我不太确定你们可以这样设置拉斐尔元素id,我想它可能会因版本而异,但不确定。出于兴趣,请尝试emitterButton.node.id='emitterButton'。我还将关注函数中的变量范围,我认为没有具体问题可以阻止它在函数中工作,但您可能希望在某个地方为emitterButton设置一个var,以明确我可能错过了它。