getAttribute разве возвращаются, не может классифицировать в IE7?

Я продолжил работу и обновил план, который я связал, с рабочим примером. Вот оно .

Что я сделал, так это создал второй массив, который действует как источник.

var sourceGroups = [
      {
      title: 'title 1',
      id:'1',
      list: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.'
    },
    {
      title: 'title 1',
      id:'2',
      list: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.'
    },
    {
      title: 'title 2',
      id:'3',
      list: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.'
    },
    {
      title: 'title 3',
      id:'4',
      list: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.'

    },
    {
      title: 'title 4',
      id:'5',
      list: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.'
    },
    {
      title: 'title 5',
      id:'6',
      list: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.'   
    }
  ];

Затем мы устанавливаем массив $scope.groups пустым.

$scope.groups = [];

Что касается вашей функции:

$scope.loadMore = function() {
      var groupToPush = sourceGroups[$scope.groups.length] || {
        title: 'title' + $scope.groups.length,
        id: $scope.groups.length,
        list: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.'
      };
      $scope.groups.push(groupToPush);
    };

... мы получаем объект с индексом, который соответствует длине вашего массива $scope.groups. Например, если длина $scope.groups равна 0, тогда он получит объект с 0-м индексом sourceGroups. Если он не может найти его, по умолчанию будет создан новый объект, который в основном генерируется.

Затем мы просто помещаем этот объект в массив $scope.groups.

Наконец, мы вызываем `$ scope.loadMore для создания экземпляра одного объекта в массиве.

$scope.loadMore();

Надеюсь, это поможет!

10
задан Nir 10 February 2009 в 08:42
поделиться

4 ответа

Стоит протестировать весь Ваш межплатформенный JavaScript, если Вы не используете что-то как jQuery для взятия боли далеко, но Класс может просто быть особым случаем.

Это должно быть межплатформенным способом получить класс:

element.className
18
ответ дан 3 December 2019 в 15:23
поделиться

IE повреждается в этом отношении. Можно получить доступ к классу в IE через getAttribute("className") но конечно это не действительно атрибут, таким образом, он не работает в! IE.

Это оставляет Вас с выбором ветвления получить element.className или ветвление к getAttribute на "имени класса" или "классе".Не очень.

2
ответ дан 3 December 2019 в 15:23
поделиться

Кто-либо знает, не работает ли getAtrribute только над 'классом' или другими атрибутами также?

Это перестало работать для всех атрибутов, где имя HTML-атрибута отличается от имени свойства DOM (имя класса, htmlFor), плюс Вы должны использовать капитализацию DOM-стиля. Это также возвращает неверный тип данных для атрибутов, свойства DOM которых не являются строками:

disabled, readOnly, checked, selected, multiple,
compact, declare, isMap, noHref, defer, noResize,
size, cols, rows, width, height, hspace, vspace,
maxLength, tabIndex, colSpan, rowSpan

и возможно другие я отсутствовал!

element.getAttribute(x)

в IE точно то же что:

element[x]

Так в целом необходимо избегать использования getAttribute и использовать простой Уровень 1/2 DOM интерфейсы HTML, такие как ‘element.className’ вместо этого.

Это наконец фиксируется в IE8.

8
ответ дан 3 December 2019 в 15:23
поделиться

Вы можете получить список всех атрибутов ваших элементов и проверить их значение таким образом. Этот фрагмент работает с браузерами IE и WebKit и возвращает строковое значение класса CSS:

var value = "";
var elements = document.getElementsByTagName("div");

for(var i = 0; i < elements.length; i++){
    if(typeof elements[i].attributes['class'] == "undefined"){
        value = elements[i].getAttribute("class"); 
    } else {
      value = elements[i].attributes['class'].nodeValue;
    }

    alert(value); // careful, this will be a lot of alerts
}
1
ответ дан 3 December 2019 в 15:23
поделиться
Другие вопросы по тегам:

Похожие вопросы: