我正在使用Raphael绘制网站上的一些元素,包括矩形和线(路径)。我已经给路径元素分配了一个id,并尝试在该行的onclick事件中访问它。但是当我弹出id时,没有显示任何内容。以下是代码片段:
function createLine()
{
var t = paper.path("M" + xLink + " " + yLink +"L" + linkWidth + " " + linkHeight);
t.attr('stroke-width','3');
t.attr('id','Hello');
t.node.onclick = processPathOnClick;
}
function processPathOnClick()
{
alert($(this).attr("id"));
}
请问上面的代码有什么问题?欢迎提供任何线索。
谢谢。
t.node.id = 'Hello'
进行比较。 - Ruan Mendes$(this.node).attr('id')
了吗?无论如何,就像已经说过的那样,你只需编写t.node.it = "Hello"
和alert(this.id)
在处理程序中即可。 - Zecc