如何将JavaScript onClick处理程序添加到嵌入式html对象?
我正在尝试将onClick处理程序添加到嵌入式对象.处理程序需要执行一个位于外部.js文件中的函数,该文件通过<script src="...
链接到当前html文件.
I'm trying to add an onClick handler to an embedded object. The handler needs to execute a function which is in an external .js file which is linked to the current html file via <script src="...
.
由于它位于其他位置,我是否需要以其他方式引用该函数?
Do I need to reference the function differently due to it being located elsewhere?
这是当前的代码(不起作用,但也不会产生任何错误):
Here is the code as it currently stands (which does not work, but also does not produce any errors):
<embed src="svg/button.svg" id="buttonEmbed" width="95" height="53"
type="image/svg+xml" onClick="buttonEvent('buttonClicked')"/>
您必须在svg内部实现onclick ,并使用svg中的javascript将其链接到外部JavaScript函数. 有关示例,请参见SVG Wiki.
You have to implement onclick inside the svg and link it to the external JavaScript function using javascript inside the svg. See the SVG wiki for examples.
更新:显然,SVG Wiki不再存在.我现在(快速)可以找到的最佳参考文献就在StackOverflow本身上,这也就不足为奇了.
Update: Apparently the SVG wiki is no more. No surprise that the best references I can now (quickly) find are on StackOverflow itself.