JQuery-获取XML元素的所有属性

JQuery-获取XML元素的所有属性,jquery,xml,sharepoint-2010,Jquery,Xml,Sharepoint 2010,我试图在XML响应中获取元素所有属性的数组 $(xData.responseXML).find("[nodeName=z:row]").each(function() { console.info($(this).attr("ows_Title")); ... 这将为ows_Title返回正确的值,但我想找出z:行具有的所有属性。我如何才能做到这一点,并让它在所有浏览器中工作?我有一个适用于FF和Chrome的方法,但它在IE中不起作用。IE似乎不知道XML元素有属性,但当我专门查找“

我试图在XML响应中获取元素所有属性的数组

$(xData.responseXML).find("[nodeName=z:row]").each(function() {
  console.info($(this).attr("ows_Title"));
  ...
这将为ows_Title返回正确的值,但我想找出z:行具有的所有属性。我如何才能做到这一点,并让它在所有浏览器中工作?我有一个适用于FF和Chrome的方法,但它在IE中不起作用。IE似乎不知道XML元素有属性,但当我专门查找“ows_Title”这样的属性时,它会看到它们

那么这个呢:

for(var key in this.attributes) {
  if(!isNaN(key)) {
    if(!prefix || this.attributes[key].name.substr(0,prefix.length) == prefix) {
      attributes.push(this.attributes[key].name);
    }
  }
}
这在IE中没有任何作用,即使在我执行console.info(THIS.attributes)时它会出现一个NamedNodeMap:

尝试:


我明白了。我最后只是重复了一遍

if(jQuery) {
  jQuery.fn.listAttributes = function() {
    var attributes = new Array();
    $(this).each(function() {
      for (var i=0; i<this.attributes.length; i++)
      {
        attributes.push(this.attributes.item(i).nodeName);
      }
    });
    return attributes;
  }
}
if(jQuery){
jQuery.fn.listAttributes=函数(){
var attributes=新数组();
$(this).each(function(){

对于(var i=0;iIt提出了一个具有正确数量属性的“NamedNodeMap”——我该怎么做呢?我在原始帖子中添加了另一个我正在尝试的东西——请看“这个怎么样?”部分。你能用你的完整示例创建一个JSFIDLE.net吗?我在SharePoint 2010列表中使用这个示例,所以我不确定如何向你展示一个功能示例,但这里是我目前用来完成任务的代码:我找到了一种解决方法。for(var I=0;I
$(xData.responseXML).find("[nodeName=z:row]").each(function() {
    console.info(this.attributes);
...
if(jQuery) {
  jQuery.fn.listAttributes = function() {
    var attributes = new Array();
    $(this).each(function() {
      for (var i=0; i<this.attributes.length; i++)
      {
        attributes.push(this.attributes.item(i).nodeName);
      }
    });
    return attributes;
  }
}