如何在JS中列出所有元素属性? [英] How to list all element attributes in JS?

查看:216
本文介绍了如何在JS中列出所有元素属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道JS中元素的所有可能属性。

I would like to know all possible attributes of an element in JS.

我做了:

s = document.getElementById("idSvg");

r = s.attributes;

alert(r.length);

...
...
<svg width="450" height="250" id="idSvg">
...
</svg>

但结果是3.似乎是我使用的属性数量(width,height和id ),但我想列出SVG元素可能具有的所有可能属性。

But the result is 3. Seems to be the number of attributes I use (width, height and id), but I would like to list ALL the possible attributes an SVG element may have.

感谢您的帮助,
Rodg

Thanks for helping, Rodg

推荐答案

你可以试试这个,但最好在w3.org上查一下

you can try this, but better off looking it up on w3.org

(function() {
    var s = document.getElementById("idSvg");

    for (var key in s) {
        document.write(key + "<br />");
    }
})();

这篇关于如何在JS中列出所有元素属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆