带有 id 的拉斐尔纸
我遇到过这样的情况:我要向页面添加多篇论文。我在每个对象上绘制了某些矩形和路径对象。我知道如何为每个这样的对象提供 id,但我还没有看到任何向论文本身添加 id 的示例。我需要更改纸张内矩形的单击事件的对象。为此,我想清除旧对象并绘制新对象。问题是我正在重复使用论文的变量。因此,该变量包含对最新论文的引用,但这不是我想要的。由于这一切,我想知道是否可以为每张纸附上一个 ID 并检索纸张,然后使用它。 欢迎任何建议。 卡维塔
嗨, 我无法从已单击的形状中获取纸质对象! this.paper、$(this).paper 不起作用。 任何帮助将不胜感激...
I have a situation where I am adding multiple papers to my page. I have drawn certain rect and path objects on each. I know how I can give id to each such object, but i haven't seen any example for adding an id to the paper itself. I need to change the objects on click event of a rect within the paper. For this I want to clear the old objects and draw new ones. The problem is that i am reusing the variable for the paper. Hence the variable contains a reference to the most recent paper which is not the one i want. Due to all this I was wondering if I could attach an id to each and retrieve the paper and then use it.
Any suggestions are welcome.
Kavita
Hi,
I am unable to get the paper object from the shape that has been clicked!!
this.paper, $(this).paper dont work.
Any help is appreciated...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个fiddle。 设置事件处理程序
如果您使用类似于在函数中引用
this
的方式 ,则它引用的是 DOM 节点,而不是 Raphael 对象。因此,您无法访问 Raphael 的属性或方法。我能够让它工作的唯一方法是在事件数据中传入 Raphael 对象,如下所示:Take a look at this fiddle. If you are setting up the event handler using something like
when you refer to
this
in the function, it refers to the DOM node, not the Raphael object. Consequently, you cannot access Raphael's properties or methods. The only way I have been able to get this to work is by passing in the Raphael object in the event data like so: