【问题标题】:Redirect to other HTML via onclick function on a SVG Element通过 SVG 元素上的 onclick 函数重定向到其他 HTML
【发布时间】:2020-06-19 00:37:38
【问题描述】:

当我点击我的 svg 元素时,我试图重定向到另一个 HTML 页面。这是我尝试过的方法。

 draw.rect(300, 250).move(1100, 200).attr ({ 
                fill: 'grey',
                stroke: '#000',
                'stroke-width': 3
                })
                .click(function() {
                   href="./index.html"
                })

希望得到一些帮助

【问题讨论】:

  • draw.rect 用于画布,而不是 SVG。你在使用一些图书馆吗?
  • 您可能想在您的.click() 函数中执行window.location.href = './index.html',对吧?

标签: javascript html svg svg.js


【解决方案1】:

您可以像这样将矩形包装在 <a> 元素中:

svg{border:solid}
<svg width="250" viewBox="-10 -10 320 220">
 <a xlink:href="https://stackoverflow.com/">
  <rect width="300" height="200" fill="grey" stroke="#000" stroke-width="3" />
 </a>
</svg>

【讨论】:

  • 这是应该的。 svg 中存在超链接是有原因的!
猜你喜欢
  • 2022-01-15
  • 2022-07-13
  • 1970-01-01
  • 2016-07-04
  • 2020-02-20
  • 1970-01-01
  • 1970-01-01
  • 2015-03-06
  • 1970-01-01
相关资源
最近更新 更多