Iframe中加载的SVG的Javascript事件

Iframe中加载的SVG的Javascript事件,javascript,jquery,svg-animate,Javascript,Jquery,Svg Animate,如何将Onclick事件处理程序附加到所有SVG路径元素?我已经在iframe中加载了SVG。我尝试使用以下命令,但单击事件未触发 jQuery(function ($) { debugger; $('path').click(function () { alert("Hello"); }); }); <iframe id="frame" src="myFile.svg" border

如何将Onclick事件处理程序附加到所有SVG路径元素?我已经在iframe中加载了SVG。我尝试使用以下命令,但单击事件未触发

jQuery(function ($) {
        debugger;
        $('path').click(function () {                
            alert("Hello");
        });
}); 
<iframe id="frame" src="myFile.svg" border="0" width="100%" height="450px"></iframe>
jQuery(函数($){
调试器;
$('path')。单击(函数(){
警惕(“你好”);
});
}); 
试试:

iframe
中的事件不会通过气泡到达包含文档。因此,如果可以用这种方式绑定事件,您需要在
iframe
中找到
path
元素,并将
单击
事件绑定到它们

$("#frame").contents().find("path").on("click", function () {
    alert("Hello");
});