简体   繁体   English

JavaScript:具名空间的特定属性?

[英]JavaScript : NameSpace of a specific attribute?

By using JavaScript, is there a way to know from which namespace does a specific attribute comes from ? 通过使用JavaScript,是否有办法知道特定属性来自哪个名称空间

I can't seem to find anything relevant about this question... 我似乎找不到与此问题相关的任何信息...

Exemple : 范例:

A DIV element with a class attribute. 具有class属性的DIV元素。 From which namespace comes the class ? 命名空间而来的

A SVG element with a viewBox attribute. 具有viewBox属性的SVG元素。 From which namespace comes the viewBox ? viewBox来自哪个命名空间

EDIT : 编辑:

If I wish to set a "xlink:href" attribute on a USE element, I'll have to specify the namespace " http://www.w3.org/1999/xlink ". 如果希望在USE元素上设置“ xlink:href”属性,则必须指定名称空间“ http://www.w3.org/1999/xlink ”。

What I'm looking for is something like : typeof attribute => namespace 我正在寻找的是这样的: typeof attribute => namespace

So... typeof "xlink:href" => " http://www.w3.org/1999/xlink " 所以... typeof“ xlink:href” =>“ http://www.w3.org/1999/xlink

I'm not asking/looking for a complete implementation that would retrieve this information. 我不是要/寻找将检索此信息的完整实现。

You can get the attributes via the attributes attribute and iterate it to get attribute names and namespaces. 您可以通过attributes属性获取属性,并对其进行迭代以获取属性名称和名称空间。 Most attributes will be in the null namespace. 大多数属性将位于空名称空间中。

 var attrs = document.getElementById("use").attributes; for(var i = 0; i < attrs.length; i++) { console.log(attrs[i].name + " " + attrs[i].namespaceURI); } 
 <svg> <use id="use" xlink:href="something" class="something"/> </svg> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM