1

Raphael.js を使用して描画された要素を取得する方法を知りたいです。getById を試しましたが、まったく機能しません。

//ユーザーがサークルをクリックすると、サークル ID が取得され、サークルと同じ ID を持つが接頭辞が異なる //四角形を取得したい。

function addCircleClick(obj)
{
    obj.click(function(event)
    {
        alert(paper+" getRect ID 1"+this.id);.
        var getRect; 
        try
        {
            var getRect  = paper.getById(this.id);////This below line(paper.getById(this.id)) is not working,even Circle object i am not able  to get
        }
        catch(e)
        {
            alert(e);//Issue here
        } 
        alert("getRect ID 2 "+getRect); 
        obj.attr({"stroke":"red"});  
    });
}       
4

1 に答える 1

2

あなたの問題は、例に示すように紙を使用しようとしていることだと思います。うまくいけば、これはあなたを助けます。

var paper = Raphael("field1", 240, 400, actions);

var attrs = {
        fill: "#FFF"    
    };

function actions() {
    var that = this;  
    var circle = that.circle(50,50,10);
    circle.attr(attrs);

    circle.click(function(event) {
        console.log(this.id); //elements id
        console.log(that.getById(this.id)); //clicked element
        console.log(paper.getById(this.id)); //doesn't work
    });
};

編集:あなたの質問を読み直して、私が誤解したかもしれないと思います。とにかく、同じIDを異なるプレフィックスで取得するという意味がよくわかりません。すべての要素は一意の番号 ID を取得します。

于 2012-05-21T17:14:47.313 に答える