【问题标题】:How to add an event on SVG click with Meteor?如何使用 Meteor 在 SVG 点击上添加事件?
【发布时间】:2017-10-16 15:35:06
【问题描述】:

我有一个 SVG,我想在上面添加一个事件监听器。
我的结构如下:

<template name="dataGraph">
  <div style="height: 100%;" class="right_col" role="main">
    <div id="logoObject">
      <object id="svg_compose" type="image/svg+xml" data="output.svg">Your browser does not support SVGs</object>
    </div>
  </div>
</template>

在我的 JavaScript 中我做到了:

Template.dataGraph.onCreated(function dataGraphOnCreated() {
});

Template.dataGraph.onRendered(function dataGraphOnRendered() {
  $(document).on('click','svg',function(){
        alert('You clicked me svg');
  });

  $(document).on('click','#svg_compose',function(){
        alert('You clicked me svg_compose');
  });

  $(document).on('click','#logoObject',function(){
        alert('You clicked me logoObject');
  });
});

Template.dataGraph.events({
  'click #svg_compose': function(e){
    console.log("we are in the svg element");
  }
});

唯一工作的听众是#logoObject之一

我的目标是当我们点击元素时打印&lt;text&gt;的内容。

你能帮我搞定吗,因为我一直在尝试,在尝试,在尝试......

【问题讨论】:

    标签: javascript jquery events meteor svg


    【解决方案1】:

    最后我知道&lt;object&gt; 不能使用事件,所以我使用了https://github.com/madebyshape/svg-convert

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-30
      • 1970-01-01
      • 1970-01-01
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 1970-01-01
      相关资源
      最近更新 更多