< object>带有svg和(双击)事件的代码 [英] <object> tag with svg and (double)click events

查看:345
本文介绍了< object>带有svg和(双击)事件的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些对象标记,每个对象标记都嵌入一个svg文件. 单击对象标签(svg),应调用javascript函数.据我了解,对象标签不支持鼠标事件.

I have some object tags that each embeds a svg file. Clicking on the object tag (the svg), should call a javascript function. As I understand, the object tag doesn't support mouse events.

我已阅读带有对象&的dousins解决方案闪光,但它们不适用于svg.

I have read of dousins solutions with object & flash, but they don't work with svg.

这不是在svg文件中编写代码的解决方案.

It is not a solution to code something in the svg file.

推荐答案

如果您不需要svg文件中的脚本编写和交互功能,则可以改用< img>标记.

You could perhaps use an <img> tag instead, if you don't need scripting and interactivity inside the svg file.

就像罗伯特·朗森(Robert Longson)所说,鼠标事件进入< object>标记,因此您需要将事件处理程序放入svg中(您可以使用脚本来执行此操作,而无需修改原始文件svg文件). 这是一个示例从引用该svg的html访问该svg的DOM.

It's like Robert Longson says, the mouse events go into the <object> tag, so you'll need to put your event handlers in the svg instead (you can do this with script, and without needing to modify the original svg file). Here's an example of how to access the DOM of the svg from the html that references it.

要澄清:

  • 获取svg根元素(请参见示例)
  • 调用rootsvg.addEventListener("click", window.parent.yourFunctionHere, false)(假设yourFunctionHere是在主html文档中的脚本中定义的函数)
  • get the root svg element (see the example)
  • call rootsvg.addEventListener("click", window.parent.yourFunctionHere, false) (assuming yourFunctionHere is a function defined in a script in the main html document)

这篇关于&lt; object&gt;带有svg和(双击)事件的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆