Javascript 对拉斐尔对象的引用

Javascript 对拉斐尔对象的引用,javascript,raphael,Javascript,Raphael,我需要在我的程序中创建几个Raphael对象。字段1和字段2是div元素。每个Raphael对象(paper1,paper2,…)都有唯一的画布,它们都需要完全相同的功能。Raphael对象需要在以后动态创建。在下面的示例代码中,我需要知道哪些对象触发mousedown事件。我还想知道在哪个div元素(这里是field1/field2)中触发了mousedown事件。我怎样才能得到信息 var myProgram = (function() { var paper1 = Raphael("fie

我需要在我的程序中创建几个Raphael对象。字段1和字段2是div元素。每个Raphael对象(paper1,paper2,…)都有唯一的画布,它们都需要完全相同的功能。Raphael对象需要在以后动态创建。在下面的示例代码中,我需要知道哪些对象触发mousedown事件。我还想知道在哪个div元素(这里是field1/field2)中触发了mousedown事件。我怎样才能得到信息

var myProgram = (function() {
var paper1 = Raphael("field1", 200, 400, fieldActions);
var paper2 = Raphael("field2", 200, 400, fieldActions);

var planeAttrs = {
    fill: "#fff"  
};

function fieldActions(){
    var that = this;

    that.field = that.rect(0, 0, 200, 400, 30);

    that.field.attr(planeAttrs);

    that.field.mousedown( function(e) {
    });
});
}());
给你:

that.field.mousedown( function(e) {
  var target = e.target;
  var svgElem = target.parentNode;
  var div = svgElem.parentNode;
  alert(div.id);
});

-矩形拉斐尔对象

this.node
-rect svg dom元素

this.paper.canvas
-svg dom元素

this.paper.canvas.parentNode
-div,id为(field2/field1),其中包含单击的svg

that.field.mousedown( function(e) {
 console.log(this, this.node, this.paper.canvas, this.paper.canvas.parentNode)
});