【问题标题】:get xlink:href using javascript (in browser)使用 javascript 获取 xlink:href (在浏览器中)
【发布时间】:2014-07-16 04:10:43
【问题描述】:

我有一个元素(在 html 中)

 <image xlink:url="https://abc" id="my_ele">

我愿意

ele = document.getElementById("my_ele")
// Now want to get https://abc

这个答案在这里Getting 'xlink:href' attribute of the SVG <image> element dynamically using JS in HTML DOM

说:

getAttributeNS('http://www.w3.org/1999/xlink', 'href');

但我不确定在我的示例中这意味着什么。

(顺便说一句,Google 文档至少在 Chrome 中显示这样的图像。不知道他们为什么不使用正确的 IMG 标签。)

【问题讨论】:

  • 在您的示例中将 href 更改为 url

标签: javascript html dom


【解决方案1】:
<image xlink:href="https://abc" id="my_ele">

ele = document.getElementById("my_ele")
var url = ele.getAttributeNS('http://www.w3.org/1999/xlink', 'href');

【讨论】:

  • 谢谢!那个 w3 url 很奇怪,但是没关系。
  • (它不允许我立即将它们标记为正确。总是有一个等待期。)
猜你喜欢
  • 2022-01-15
  • 1970-01-01
  • 2021-01-05
  • 2011-03-20
  • 2012-04-08
  • 2014-06-26
  • 2014-05-31
  • 1970-01-01
  • 2012-01-15
相关资源
最近更新 更多