输出元素的所有set属性

ama*_*eur 5 javascript jquery

我有一个jquery对象,它表示页面上的输入按钮元素.如何使用jquery通过console.log输出此元素的所有属性/属性?

Mik*_*ace 10

假设页面的HTML是

<body>
  <img id="smile" class="big" alt="smile" madeupattribute="yep" src="http://mikegrace.s3.amazonaws.com/forums/stack-overflow/smile.png"/>
</body>
Run Code Online (Sandbox Code Playgroud)

你能做到的

var domElement = $("img")[0] // [0] returns the first DOM element that jQuery found
$(domElement.attributes).each(function(index, attribute) {
  console.log("Attribute:"+attribute.nodeName+" | Value:"+attribute.nodeValue);
});
Run Code Online (Sandbox Code Playgroud)

示例页面 => http://mikegrace.s3.amazonaws.com/forums/stack-overflow/example-get-element-attributes-jquery.html

示例页面控制台输出

替代文字