Cakephp JsHelper和SVG
是否可以在cakephp中将事件绑定到svg节点元素 我让RequestHandler正确地处理divs,但我 要求在页面中设置具有多个可单击区域的SVG 如果我执行类似以下代码的操作:Cakephp JsHelper和SVG,cakephp,svg,Cakephp,Svg,是否可以在cakephp中将事件绑定到svg节点元素 我让RequestHandler正确地处理divs,但我 要求在页面中设置具有多个可单击区域的SVG 如果我执行类似以下代码的操作: <object id="mysvg" type="image/svg+xml" data="/img/mysvg.svg"> <p>Error, browser must support "SVG"</p> </object> 它似乎不起作用。 有人能分享
<object id="mysvg" type="image/svg+xml" data="/img/mysvg.svg">
<p>Error, browser must support "SVG"</p>
</object>
它似乎不起作用。
有人能分享一些想法吗
最好的问候回答我自己的问题,以防其他人也需要 可能有更好的解决方案,如果您找到了,请分享: 不管怎么说,这一个符合它的目的。因为我找不到办法 与svg节点关联的事件我为该部分添加了javascript
<script type="text/javascript">
//<![CDATA[
var a = document.getElementById("mysvg");
//it's important to add an load event listener to the object, as it will load the svg doc asynchronously
a.addEventListener("load",function(){
var svgDoc = a.contentDocument; //get the inner DOM
var delta = svgDoc.getElementById("mysvg-nodeID"); //get the inner element by id
delta.addEventListener("mousedown",
function(){
<?php
echo $this->Js->request(array('action' => 'myaction', 'param01'),array('async' => true, 'update' => '#main_div'));
?>
},false); //add behaviour
</script>
对象代码的Id&在jshelper中使用的Id似乎不同。请检查。感谢Rikesh的反馈。但我指的是SVG中特定节点的Id,而不是整个对象。小提琴示例
<script type="text/javascript">
//<![CDATA[
var a = document.getElementById("mysvg");
//it's important to add an load event listener to the object, as it will load the svg doc asynchronously
a.addEventListener("load",function(){
var svgDoc = a.contentDocument; //get the inner DOM
var delta = svgDoc.getElementById("mysvg-nodeID"); //get the inner element by id
delta.addEventListener("mousedown",
function(){
<?php
echo $this->Js->request(array('action' => 'myaction', 'param01'),array('async' => true, 'update' => '#main_div'));
?>
},false); //add behaviour
</script>